package com.dmgis.qxfw.dataservice.pages.controller;

import com.dmgis.entity.DmMapPoint;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.Results;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.Results1;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.tour_stations;
import com.dmgis.qxfw.dataservice.businessservice.cdtour.service.ITourInfoSearchService;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.TourStation;
import com.dmgis.qxfw.dataservice.businessservice.common.util.FileUtil;
import com.dmgis.qxfw.dataservice.businessservice.common.util.WebCtrlData;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.FileRequestService;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.MongoService1;
import com.dmgis.qxfw.dataservice.gisservice.service.ITransformService;
import com.dmgis.qxfw.dataservice.pages.service.IComDisplayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @className ComDisplayController
 * @Description TODO 综合展示
 * @Author lhfy
 * @Version 1.0
 */
@Controller
@RequestMapping("/ComDisplay")
public class ComDisplayController {

    @Autowired
    private IComDisplayService comDisplayService;
    @Autowired
    private  ComDisplayController comDisplayController;
    @Resource
    ITourInfoSearchService tourService;
    @Resource
    private ITransformService transformService;

    private   String operatingSystem;

    @Autowired
    public void TourInfoSearchController(String operatingSystem) {
        this.operatingSystem = operatingSystem;
    }
   //MongoService1 ms = new MongoService1();
   FileRequestService ms = new FileRequestService();

    /**
     * 实况信息统计
     */
    @GetMapping("/display")
    @ResponseBody
    public Results display(int hour) {
        try {
            List<Map<String, Object>> list = comDisplayService.display(hour);


            return Results.success("实况信息统计", list.size(), list);

        } catch (Exception e) {
            return Results.fail(e.getMessage());
        }
    }

    @GetMapping("/display1")
    @ResponseBody
    public Results display1(int hour) {
        try {
            List<Object> list = comDisplayService.display1(hour);
            return Results.success("实况信息站点个数统计", list.size(), list);

        } catch (Exception e) {
            return Results.fail(e.getMessage());
        }
    }


    /**
     * 获取检测站名称
     */
    @GetMapping("/getStationName")
    @ResponseBody
    public Results getStationName() {
        try {
            List<Map<String, Object>> res = comDisplayService.getStationName();
            return Results.success("获取检测站名称", res.size(), res);
        } catch (Exception e) {
            return Results.fail(e.getMessage());
        }
    }

    /*
    * 获取景区过去24小时站点数据*/
    @GetMapping("/get24HourInfoTour")
    @ResponseBody
    public Results get24HourInfoTour(HttpServletRequest request, Model model) {
        String type = request.getParameter("type");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 获取当前时间
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, -24);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        String startTime = simpleDateFormat.format(calendar.getTime());//24h
        // 处理 endTime
        calendar.setTime(date);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 获取调整后的 endTime
        String endTime = simpleDateFormat.format(calendar.getTime());
        StringBuilder sql1 = new StringBuilder();
        List<Map<String, Object>> res1 = null;
        try {
            StringBuilder sql = new StringBuilder();
            sql.append("select stationid,longitude,latitude,stationname ")
                    .append("from tour_stations ");
            List<Map<String, Object>> res = comDisplayService.getStationInfo(sql.toString());
            // 使用 StringJoiner 来连接结果
            StringJoiner joiner = new StringJoiner(",");

            // 遍历 res 列表，提取每个 stationid，并在添加到 joiner 时加上单引号
            for (Map<String, Object> station : res) {
                String stationId1 = (String) station.get("stationid");
                joiner.add("'" + stationId1 + "'");  // 在每个 stationid 前后加上单引号
            }
            // 最终结果就是你想要的字符串
            String result = joiner.toString();

            if (type.equals("maxtemp")){
                sql1.append("select stationid,longitude,latitude,stationname,maxtemp AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime between '" + startTime + "' and '" + endTime + "' ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo(sql1.toString());
            }else if (type.equals("rain")){
                sql1.append("select stationid,longitude,latitude,stationname,rain AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime between '" + startTime + "' and '" + endTime + "' ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo(sql1.toString());
            }else if (type.equals("wind")){
                sql1.append("select stationid,longitude,latitude,stationname,instantwindv AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime between '" + startTime + "' and '" + endTime + "' ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo(sql1.toString());
            }else if (type.equals("mintemp")){
                sql1.append("select stationid,longitude,latitude,stationname,mintemp AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime between '" + startTime + "' and '" + endTime + "' ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo(sql1.toString());
            }else if (type.equals("visibility")){
                sql1.append("select stationid,longitude,latitude,stationname,visibility AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime between '" + startTime + "' and '" + endTime + "' ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo(sql1.toString());
            }


        }catch (Exception e){
            return Results.fail(e.getMessage());
        }
        return Results.success("获取伊犁州下全部站点过去24小时信息", 1, res1);
    }
    /*获取马拉松路线*/
    @GetMapping("/getMarathonInfo")
    @ResponseBody
    public Results getMarathonInfo(HttpServletRequest request, Model model) {
        StringBuilder sql = new StringBuilder();
        sql.append("select * from marathon_info");
        List<Map<String, Object>> res = null;
        List<List<Double>> res1 = new ArrayList<>();  // 修改成 List<List<Double>> 类型
        try {
            res = comDisplayService.getMarathonInfo(sql.toString());
            String dataString = res.get(0).get("pos").toString();
            // 去除首尾的花括号
            dataString = dataString.substring(1, dataString.length() - 1);

            // 按分号分割坐标对
            String[] coordinates = dataString.split(";");

            // 遍历每个坐标点
            for (String coord : coordinates) {
                if (!coord.isEmpty()) { // 忽略空字符串
                    String[] latLon = coord.split(",");
                    if (latLon.length == 2) {
                        try {
                            double latitude = Double.parseDouble(latLon[0].trim());
                            double longitude = Double.parseDouble(latLon[1].trim());

                            // 创建一个 List 来表示单个坐标对
                            List<Double> coordList = new ArrayList<>();
                            coordList.add(latitude);
                            coordList.add(longitude);

                            // 将坐标对添加到结果列表中
                            res1.add(coordList);
                        } catch (NumberFormatException e) {
                            // 如果解析出错，输出错误信息
                            System.err.println("坐标解析错误: " + coord);
                        }
                    }
                }
            }
            // 返回成功响应
        } catch (Exception e) {
            return Results.fail(e.getMessage());
        }
        return Results.success("获取马拉松路线", 1, res1);
    }




    /*获取伊犁州下全部站点过去24小时数据
    * */
        @RequestMapping("/get24HourYiLi")
        @ResponseBody
        public Results get24HourYiLi(HttpServletRequest request, Model model) {
            String type = request.getParameter("type");
            String county1 =  "'伊宁市','察布查尔锡伯自治县','奎屯市','霍尔果斯市','伊宁县','巩留县','霍城县','新源县','昭苏县','特克斯县','尼勒克县'";
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            // 获取当前时间
            Date date = new Date();
            // 获取 Calendar 实例并设置当前时间
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.HOUR_OF_DAY, -24);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            String startTime = simpleDateFormat.format(calendar.getTime());//24h
           // 处理 endTime
            calendar.setTime(date);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            // 获取调整后的 endTime
            String endTime = simpleDateFormat.format(calendar.getTime());
            StringBuilder sql1 = new StringBuilder();
            List<Map<String, Object>> res1 = null;
            try {
               StringBuilder sql = new StringBuilder();
               sql.append("select stationid,longitude,latitude,stationname ")
                       .append("from smallscale_station ")
                       .append("where county IN (" + county1 + ")");
               List<Map<String, Object>> res = comDisplayService.getStationInfo(sql.toString());
               // 使用 StringJoiner 来连接结果
               StringJoiner joiner = new StringJoiner(",");

               // 遍历 res 列表，提取每个 stationid，并在添加到 joiner 时加上单引号
               for (Map<String, Object> station : res) {
                   String stationId1 = (String) station.get("stationid");
                   joiner.add("'" + stationId1 + "'");  // 在每个 stationid 前后加上单引号
               }
               // 最终结果就是你想要的字符串
               String result = joiner.toString();

                if (type.equals("maxtemp")){
                    sql1.append("select stationid,longitude,latitude,stationname,MAX(maxtemp) AS value ")
                            .append("from msgmediumsmallscale ")
                            .append("where stationid in (" + result + ") ")
                            .append("and observtime between '" + startTime + "' and '" + endTime + "' ")
                            .append("GROUP BY stationid,longitude,latitude,stationname ")
                            .append("ORDER BY value DESC ");
                    res1 = comDisplayService.getMhInfo3(sql1.toString());
                }else if (type.equals("rain")){
                    sql1.append("select stationid,longitude,latitude,stationname,SUM(rain) AS value ")
                            .append("from msgmediumsmallscale ")
                            .append("where stationid in (" + result + ") ")
                            .append("and observtime between '" + startTime + "' and '" + endTime + "' ")
                            .append("GROUP BY stationid,longitude,latitude,stationname ")
                            .append("ORDER BY value DESC ");
                    res1 = comDisplayService.getMhInfo3(sql1.toString());
                }else if (type.equals("wind")){
                    sql1.append("select stationid,longitude,latitude,stationname,MAX(instantwindv) AS value ")
                            .append("from msgmediumsmallscale ")
                            .append("where stationid in (" + result + ") ")
                            .append("and observtime between '" + startTime + "' and '" + endTime + "' ")
                            .append("GROUP BY stationid,longitude,latitude,stationname ")
                            .append("ORDER BY value DESC ");
                    res1 = comDisplayService.getMhInfo3(sql1.toString());
                }else if (type.equals("mintemp")){
                    sql1.append("select stationid,longitude,latitude,stationname,MIN(mintemp) AS value ")
                            .append("from msgmediumsmallscale ")
                            .append("where stationid in (" + result + ") ")
                            .append("and observtime between '" + startTime + "' and '" + endTime + "' ")
                            .append("GROUP BY stationid,longitude,latitude,stationname ")
                            .append("ORDER BY value DESC ");
                    res1 = comDisplayService.getMhInfo3(sql1.toString());
                }else if (type.equals("visibility")){
                    sql1.append("select stationid,longitude,latitude,stationname,max(visibility) AS value ")
                            .append("from msgmediumsmallscale ")
                            .append("where stationid in (" + result + ") ")
                            .append("and observtime between '" + startTime + "' and '" + endTime + "' ")
                            .append("GROUP BY stationid,longitude,latitude,stationname ")
                            .append("ORDER BY value DESC ");
                    res1 = comDisplayService.getMhInfo3(sql1.toString());
                }


           }catch (Exception e){
               return Results.fail(e.getMessage());
           }
           return Results.success("获取伊犁州下全部站点过去24小时信息", 1, res1);
        }

        /*获取大屏左侧云地闪云间闪*/
    @GetMapping("/getCloudInfo")
    @ResponseBody
    public Results getCloudInfo(HttpServletRequest request, Model model) {
        String type = request.getParameter("type");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 获取当前时间
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 将时间减去1小时
        calendar.add(Calendar.HOUR_OF_DAY, -24);
        // 将分钟、秒钟和毫秒设置为0
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 格式化并输出结果
        String satrtTime = simpleDateFormat.format(calendar.getTime());//24h
        // 处理 endTime
        calendar.setTime(date);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 获取调整后的 endTime
        String endTime = simpleDateFormat.format(calendar.getTime());
        StringBuilder sql = new StringBuilder();
        sql.append("select lon,lat,strength ")
                .append("from raiden ")
                .append("where locatetype ='" + type + "' AND ")
                .append("observetime between '" +satrtTime+"' and '"+endTime+"' and ")
                .append("city = '伊犁哈萨克自治州' ");
        List<Map<String, Object>> res = new ArrayList<>();
        try {
         res = comDisplayService.getlightningInfo(sql.toString());
        } catch (Exception e) {
            return Results.fail(e.getMessage());
        }
        return Results.success("获取云地闪云间闪", 1, res);
    }

    /*获取决策大屏伊犁州搜索1、3、24降水等数据*/
    @GetMapping("/getAllInfoByLiLi")
    @ResponseBody
    public Results1 getAllInfoByLiLi(HttpServletRequest request, Model model) {
        String type = request.getParameter("type");
        String county1 = "'伊宁市','察布查尔锡伯自治县','奎屯市','霍尔果斯市','伊宁县','巩留县','霍城县','新源县','昭苏县','特克斯县','尼勒克县'";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 获取当前时间
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 将时间减去1小时
        calendar.add(Calendar.HOUR_OF_DAY, -1);
        // 将分钟、秒钟和毫秒设置为0
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 格式化并输出结果
        String one = simpleDateFormat.format(calendar.getTime());//1h


        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, -3);
        // 将分钟、秒钟和毫秒设置为0
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 格式化并输出结果
        String there = simpleDateFormat.format(calendar.getTime());//3h

        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, -6);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        String six = simpleDateFormat.format(calendar.getTime());//6h

        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, -12);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        String twelve = simpleDateFormat.format(calendar.getTime());//12h

        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, -24);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        String ts = simpleDateFormat.format(calendar.getTime());//24h
        // 处理 endTime
        calendar.setTime(date);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 获取调整后的 endTime
        String endTime = simpleDateFormat.format(calendar.getTime());

        calendar.setTime(date);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        String endTime1 = simpleDateFormat.format(calendar.getTime());//
        List<Map<String, Object>> res1 = null;
        List<Map<String, Object>> getcolor = null;
        List<Map<String, Object>> res2 = null;
        try {
            StringBuilder sql = new StringBuilder();
            sql.append("select stationid,longitude,latitude,stationname ")
                    .append("from smallscale_station ")
                    .append("where county IN (" + county1 + ")");
            List<Map<String, Object>> res = comDisplayService.getStationInfo(sql.toString());
            // 使用 StringJoiner 来连接结果
            StringJoiner joiner = new StringJoiner(",");

            // 遍历 res 列表，提取每个 stationid，并在添加到 joiner 时加上单引号
            for (Map<String, Object> station : res) {
                String stationId1 = (String) station.get("stationid");
                joiner.add("'" + stationId1 + "'");  // 在每个 stationid 前后加上单引号
            }

            // 最终结果就是你想要的字符串
            String result = joiner.toString();
            StringBuilder sql1 = new StringBuilder();
            StringBuilder sql2 = new StringBuilder();
            if (type.equals("temp")) {
                sql1.append("select stationid,longitude,latitude,stationname,drybulbtemp AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime = '" + endTime + "' ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo3(sql1.toString());
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '温度' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }

                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                for (Map<String, Object> row : res1) {
                    Double rainValue = (Double) row.get("value");
                    String color = getColorForRainValue(rainValue, rainToColorMap);
                    row.put("color", color);
                }
            } else if (type.equals("wind")) {
                sql1.append("select stationid,longitude,latitude,stationname,instantwindd,instantwindv AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime = '" + endTime + "' ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo1(sql1.toString());
                for (Map<String, Object> map1 : res1) {
                     int windd = WebCtrlData.FengSuToFengJi((Double) map1.get("value"));
                     map1.put("windd", windd);
                }
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '风速' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }

                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                for (Map<String, Object> row : res1) {
                    Double rainValue = (Double) row.get("value");
                    String color = getColorForRainValue(rainValue, rainToColorMap);
                    row.put("color", color);
                }
            }  else if (type.equals("visibility")) {
                sql1.append("select stationid,longitude,latitude,stationname,visibility AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime = '" + endTime + "' ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo3(sql1.toString());
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '能见度' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                for (Map<String, Object> row : res1) {
                    Double rainValue = (Double) row.get("value");
                    String color = getColorForRainValue(rainValue, rainToColorMap);
                    row.put("color", color);
                }
            } else if (type.equals("1h")) {
                sql1.append("select stationid,longitude,latitude,stationname,rain AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime  = '" + endTime + "' ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo3(sql1.toString());
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '1小时雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                for (Map<String, Object> row : res1) {
                    Double rainValue = (Double) row.get("value");
                    String color = getColorForRainValue(rainValue, rainToColorMap);
                    row.put("color", color);
                }
            } else if (type.equals("3h")) {
                sql1.append("select stationid,longitude,latitude,stationname, SUM(rain) AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime between '" + there + "' and '" + endTime + "' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo3(sql1.toString());
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '3小时雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                for (Map<String, Object> row : res1) {
                    Double rainValue = (Double) row.get("value");
                    String color = getColorForRainValue(rainValue, rainToColorMap);
                    row.put("color", color);
                }
            } else if (type.equals("6h")) {
                sql1.append("select stationid,longitude,latitude,stationname, SUM(rain) AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime between '" + six + "' and '" + endTime + "' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo3(sql1.toString());
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '6小时雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                for (Map<String, Object> row : res1) {
                    Double rainValue = (Double) row.get("value");
                    String color = getColorForRainValue(rainValue, rainToColorMap);
                    row.put("color", color);
                }
            }else if (type.equals("12h")){
                sql1.append("select stationid,longitude,latitude,stationname, SUM(rain) AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime between '" + twelve + "' and '" + endTime + "' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo3(sql1.toString());
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '12小时雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                for (Map<String, Object> row : res1) {
                    Double rainValue = (Double) row.get("value");
                    String color = getColorForRainValue(rainValue, rainToColorMap);
                    row.put("color", color);
                }
            } else if (type.equals("24h")) {
                sql1.append("select stationid,longitude,latitude,stationname, SUM(rain) AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime between '" + ts + "' and '" + endTime + "' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo3(sql1.toString());
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '24小时雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue =(Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                for (Map<String, Object> row : res1) {
                    Double rainValue = (Double) row.get("value");
                    String color = getColorForRainValue(rainValue, rainToColorMap);
                    row.put("color", color);
                }
            }
        } catch (Exception e) {
            return Results1.fail(e.getMessage());
        }

        return Results1.success("大屏左侧搜索小时降水气温大风能见度等", 1, res1,getcolor);
    }

    /**
     *
     * 获取分钟小时降水温度等数据
     */
    @GetMapping("/getMinAndHourInfo")
    @ResponseBody
    public Results1 getMinAndHourInfo(HttpServletRequest request, Model model) {
        String county = request.getParameter("advname");
        String type = request.getParameter("type");
        String county1 = "";
        switch (county) {
            case "伊犁州直":
                county1 = "'伊宁市','察布查尔锡伯自治县','奎屯市','霍尔果斯市','伊宁县','巩留县','霍城县','新源县','昭苏县','特克斯县','尼勒克县'";
                break;
            case "伊犁河谷":
                county1 = "'伊宁市','察布查尔锡伯自治县','霍尔果斯市','伊宁县','巩留县','霍城县','新源县','昭苏县','特克斯县','尼勒克县'";
                break;
            case "察县":
                county1 = "'察布查尔锡伯自治县'";
                break;
            case "伊宁市":
                county1 = "'伊宁市'";
                break;
            case "奎屯市":
                county1 = "'奎屯市'";
                break;
            case "霍尔果斯市":
                county1 = "'霍尔果斯市'";
                break;
            case "伊宁县":
                county1 = "'伊宁县'";
                break;
            case "巩留县":
                county1 = "'巩留县'";
                break;
            case "霍城县":
                county1 = "'霍城县'";
                break;
            case "新源县":
                county1 = "'新源县'";
                break;
            case "昭苏县":
                county1 = "'昭苏县'";
                break;
            case "特克斯县":
                county1 = "'特克斯县'";
                break;
            case "尼勒克县":
                county1 = "'尼勒克县'";
                break;
            default:
                return null;

        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 获取当前时间
        Date date = new Date();
        // // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        // calendar.setTime(date);
        // // 将时间减去1小时
        calendar.add(Calendar.HOUR_OF_DAY, -1);
        // 将分钟、秒钟和毫秒设置为0
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 格式化并输出结果
       // String one = simpleDateFormat.format(calendar.getTime());//1h
        String endTime = simpleDateFormat.format(calendar.getTime());

        List<Map<String, Object>> res1 = new ArrayList<>();
        List<Map<String, Object>> getcolor = new ArrayList<>();
        List<Map<String, Object>> res2 = new ArrayList<>();
        List<Map<String, Object>> res3 = new ArrayList<>();
        List<Map<String, Object>> res4 = new ArrayList<>();
        List<Map<String, Object>> res5 = new ArrayList<>();
        List<Map<String, Object>> res6 = new ArrayList<>();
        List<Map<String, Object>> res7 = new ArrayList<>();
        List<Map<String, Object>> res8 = new ArrayList<>();
        List<Map<String, Object>> res9 = new ArrayList<>();
        List<Map<String, Object>> res10 = new ArrayList<>();
        try {
            StringBuilder sql = new StringBuilder();
            sql.append("select stationid,longitude,latitude,stationname,county ")
                    .append("from smallscale_station ")
                    .append("where county IN (" + county1 + ")");
            List<Map<String, Object>> res = comDisplayService.getStationInfo1(sql.toString());
            // 使用 StringJoiner 来连接结果
            StringJoiner joiner = new StringJoiner(",");

            // 遍历 res 列表，提取每个 stationid，并在添加到 joiner 时加上单引号
            for (Map<String, Object> station : res) {
                String stationId1 = (String) station.get("stationid");
                joiner.add("'" + stationId1 + "'");  // 在每个 stationid 前后加上单引号
            }
            // 最终结果就是你想要的字符串
            String result = joiner.toString();
            StringBuilder sql1 = new StringBuilder();
            StringBuilder sql2 = new StringBuilder();
            StringBuilder sql3 = new StringBuilder();
            StringBuilder sql4 = new StringBuilder();
            StringBuilder sql5 = new StringBuilder();
            StringBuilder sql6 = new StringBuilder();
            StringBuilder sql7 = new StringBuilder();
            StringBuilder sql8 = new StringBuilder();
            StringBuilder sql9 = new StringBuilder();
            sql3.append("select datetime ")
                    .append("from msg_other_minute ")
                    .append("where station_id_c like '5%' ")
                    .append("AND city like '%伊犁%' ")
                    .append("ORDER BY datetime DESC LIMIT 1 ");
            res2 = comDisplayService.getNewShiJian(sql3.toString());
            sql4.append("select datetime ")
                    .append("from msg_other_minute ")
                    .append("where station_id_c like 'Y%' ")
                    .append("AND city like '%伊犁%' ")
                    .append("ORDER BY datetime DESC LIMIT 1 ");
            res3 = comDisplayService.getNewShiJian(sql4.toString());
            sql5.append("select datetime ")
                    .append("from msg_rain_minute ")
                    .append("where station_id_c like '5%' ")
                    .append("AND city like '%伊犁%' ")
                    .append("ORDER BY datetime DESC LIMIT 1 ");
            res4 = comDisplayService.getNewShiJian(sql5.toString());
            sql6.append("select datetime ")
                    .append("from msg_rain_minute ")
                    .append("where station_id_c like 'Y%' ")
                    .append("AND city like '%伊犁%' ")
                    .append("ORDER BY datetime DESC LIMIT 1 ");
            res5 = comDisplayService.getNewShiJian(sql6.toString());
            String guoJiatime = res2.get(0).get("datetime").toString();//国家站最新时间
            String quYutime = res3.get(0).get("datetime").toString();
            String guoJiatimeR = res4.get(0).get("datetime").toString();//国家站最新时间
            String quYutimeR = res5.get(0).get("datetime").toString();
            SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date guoJ = sim.parse(guoJiatime);
            Date guoJR = sim.parse(guoJiatimeR);
            Calendar instance = Calendar.getInstance();
            instance.setTime(guoJ);
            instance.add(Calendar.MINUTE, -15);
            // 获取减去 10 分钟后的时间
            Date newDate = instance.getTime();
            // 格式化新的时间为字符串
            String guoJiatime1 = sim.format(newDate);
            instance.setTime(guoJR);
            instance.add(Calendar.MINUTE, -15);
            // 获取减去 10 分钟后的时间
            Date newDater = instance.getTime();
            // 格式化新的时间为字符串
            String guoJiatime1r = sim.format(newDater);
            Date quY = sim.parse(quYutime);
            Date quYR = sim.parse(quYutimeR);
            instance.setTime(quY);
            instance.add(Calendar.MINUTE, -15);
            // 获取减去 10 分钟后的时间
            Date newDate1 = instance.getTime();
            // 格式化新的时间为字符串
            String quYutime1 = sim.format(newDate1);
            instance.setTime(quYR);
            instance.add(Calendar.MINUTE, -15);
            // 获取减去 10 分钟后的时间
            Date newDate1r = instance.getTime();
            // 格式化新的时间为字符串
            String quYutime1r = sim.format(newDate1r);
            sql8.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                    .append("from msg_rain_minute ")
                    .append("where station_id_c in (" + result + ") ")
                    .append("and datetime between '" + guoJiatime1r + "' and '" + guoJiatimeR + "' ")
                    .append("and station_id_c like '5%' ")
                    .append("AND city like '%伊犁%' ")
                    .append("and pre <> '-65535' ")
                    .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                    .append("ORDER BY value DESC ");
            res8 = comDisplayService.getMhInfo(sql8.toString());
            sql9.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                    .append("from msg_rain_minute ")
                    .append("where station_id_c in (" + result + ") ")
                    .append("and datetime between '" + quYutime1r + "' and '" + quYutimeR + "' ")
                    .append("and station_id_c like 'Y%' ")
                    .append("AND city like '%伊犁%' ")
                    .append("and pre <> '-65535' ")
                    .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                    .append("ORDER BY value DESC ");
            res9 = comDisplayService.getMhInfo(sql9.toString());
            if (res8.size() > 0){
                res10.addAll(res8);
            }
            if (res9.size() >0){
                res10.addAll(res9);
            }
            if (type.equals("temp")) {
                sql1.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,MAX(tem) AS value,cnty  ")
                        .append("from msg_other_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + guoJiatime1 + "' and '" + guoJiatime + "' ")
                        .append("and station_id_c like '5%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and tem <> '-65535' ")
                        .append("GROUP BY station_id_c, lon, lat, station_name,cnty ")
                        .append("ORDER BY value DESC  ");
                res7 = comDisplayService.getMhInfo(sql1.toString());
                sql7.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,MAX(tem) AS value,cnty  ")
                        .append("from msg_other_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + quYutime1 + "' and '" + quYutime + "' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and tem <> '-65535' ")
                        .append("GROUP BY station_id_c, lon, lat, station_name,cnty ")
                        .append("ORDER BY value DESC  ");
                res6 = comDisplayService.getMhInfo(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                if (res1.isEmpty()) {
                    int Y = res.size() - res10.size();
                    int N = res10.size();
                    HashMap<String, Object>  num1 = new HashMap<>();
                    //存储正常异常站点数量
                    num1.put("YES",N);num1.put("NO",Y);num1.put("1",0);//存储图例对应个数
                    num1.put("2",0);num1.put("3",0);num1.put("4",0);
                    num1.put("5",0);num1.put("6",0);num1.put("7",0);
                    num1.put("8",0);num1.put("9",0);num1.put("10",0);
                    num1.put("11",0);num1.put("12",0);num1.put("13",0);
                    num1.put("14",0);num1.put("15",0);num1.put("16",0);
                    res2.add(num1);
                    for (Map<String, Object> re : res) {
                        String stationid = (String) re.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res10) {
                            String quYuId = (String) quYu.get("stationid");
                            if (stationid.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        if (found){
                            HashMap<String, Object> map = new HashMap<>();
                            String quYuId = (String) re.get("stationid");
                            Double quYuLongitude = (Double) re.get("longitude");
                            Double quYuLatitude = (Double) re.get("latitude");
                            String quYuStationname = (String) re.get("stationname");
                            String quYuCounty = (String) re.get("cnty");
                            map.put("stationid", quYuId);
                            map.put("longitude", quYuLongitude);
                            map.put("latitude", quYuLatitude);
                            map.put("stationname", quYuStationname);
                            map.put("cnty", quYuCounty);
                            map.put("value", "Y");
                            res1.add(map);
                        }else {
                            HashMap<String, Object> map = new HashMap<>();
                            String quYuId = (String) re.get("stationid");
                            Double quYuLongitude = (Double) re.get("longitude");
                            Double quYuLatitude = (Double) re.get("latitude");
                            String quYuStationname = (String) re.get("stationname");
                            String quYuCounty = (String) re.get("cnty");
                            map.put("stationid", quYuId);
                            map.put("longitude", quYuLongitude);
                            map.put("latitude", quYuLatitude);
                            map.put("stationname", quYuStationname);
                            map.put("cnty", quYuCounty);
                            map.put("value", "N");
                            res1.add(map);
                        }
                    }
                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0;int tu5=0;int tu6=0;
                    int tu7=0;int tu8=0;int tu9=0;
                    int tu10=0;int tu11=0;int tu12=0;
                    int tu13=0;int tu14=0;int tu15=0;int tu16=0;
                    for (Map<String, Object> tu : res1) {
                        Double value = (Double) tu.get("value");
                        if(value < -12){
                            tu1++;
                        } else if (value >= -12 && value < -8) {
                            tu2++;
                        } else if (value >= -8 && value < -4) {
                            tu3++;
                        } else if (value >= -4 && value <0) {
                            tu4++;
                        }else if (value >= 0 && value <4) {
                            tu5++;
                        }else if (value >= 4 && value < 8) {
                            tu6++;
                        }else if (value >= 8 && value < 12) {
                            tu7++;
                        }else if (value >= 12 && value < 16) {
                            tu8++;
                        }else if (value >= 16 && value < 20) {
                            tu9++;
                        }else if (value >= 20 && value < 24) {
                            tu10++;
                        }else if (value >= 24 && value < 28) {
                            tu11++;
                        }else if (value >= 28 && value < 32) {
                            tu12++;
                        }else if (value >= 32 && value < 35) {
                            tu13++;
                        }else if (value >= 35 && value < 37) {
                            tu14++;
                        }else if (value >= 37 && value < 40) {
                            tu15++;
                        }else {
                            tu16++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4);num.put("5", tu5);num.put("6", tu6);
                    num.put("7", tu7);num.put("8", tu8);num.put("9", tu9);
                    num.put("10", tu10);num.put("11", tu11);num.put("12", tu12);
                    num.put("13", tu13);num.put("14", tu14);num.put("15", tu15);num.put("16", tu16);
                    for (Map<String, Object> guoJia : res10) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCounty = (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCounty);
                            newQuYu.put("value", "Y");
                            res1.add(newQuYu);
                        }
                    }
                    int Y = res.size() - res1.size();
                    int N = res1.size();
                    num.put("YES",N);
                    num.put("NO",Y);
                    res2.add(num);
                    for (Map<String, Object> finalA : res) {
                        String guoJiaId = (String) finalA.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) finalA.get("stationid");
                            Double quYuLongitude = (Double) finalA.get("longitude");
                            Double quYuLatitude = (Double) finalA.get("latitude");
                            String quYuStationname = (String) finalA.get("stationname");
                            String quYuCounty = (String) finalA.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCounty);
                            newQuYu.put("value", "N");
                            res1.add(newQuYu);
                        }
                    }
                }
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '温度' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                        String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                        map.put("16color", colorValue);

                }
            Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
            for (Map<String, Object> row : getcolor) {
                Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                rainToColorMap.put(rainValue, colorValue);
            }
            // for (Map<String, Object> row : res1) {
            //     Double rainValue = (Double) row.get("value");
            //     String color = getColorForRainValue(rainValue, rainToColorMap);
            //     row.put("color", color);
            // }
            } else if (type.equals("bestWind")) {
                sql1.append("WITH RankedData AS (select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,win_d_avg_2mi AS instantwindd,win_s_avg_2mi AS windspeed,cnty,  ")
                        .append("ROW_NUMBER() OVER (PARTITION BY station_id_c ORDER BY win_s_avg_2mi DESC) AS rn ")
                        .append("from msg_other_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + guoJiatime1 + "' and '" + guoJiatime + "' ")
                        .append("and station_id_c like '5%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and win_s_avg_2mi <> '-65535') ")
                        .append("SELECT stationid,longitude,latitude,stationname,instantwindd,windspeed AS value,cnty ")
                        .append("FROM RankedData ")
                        .append("WHERE rn = 1 ")
                        .append("ORDER BY windspeed DESC ");
                res7 = comDisplayService.getMhInfo2(sql1.toString());
                sql7.append("WITH RankedData AS (select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,win_d_avg_2mi AS instantwindd,win_s_avg_2mi AS windspeed,cnty,  ")
                        .append("ROW_NUMBER() OVER (PARTITION BY station_id_c ORDER BY win_s_avg_2mi DESC) AS rn ")
                        .append("from msg_other_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + quYutime1 + "' and '" + quYutime + "' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and win_s_avg_2mi <> '-65535') ")
                        .append("SELECT stationid,longitude,latitude,stationname,instantwindd,windspeed AS value,cnty ")
                        .append("FROM RankedData ")
                        .append("WHERE rn = 1 ")
                        .append("ORDER BY windspeed DESC ");
                res6 = comDisplayService.getMhInfo2(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                if (res1.isEmpty()) {
                    int Y = res.size() - res10.size();
                    int N = res10.size();
                    HashMap<String, Object>  num1 = new HashMap<>();//存储正常异常站点数量
                    num1.put("YES",N);num1.put("NO",Y);num1.put("1",0);//存储图例对应个数
                    num1.put("2",0);num1.put("3",0);num1.put("4",0);
                    num1.put("5",0);num1.put("6",0);num1.put("7",0);
                    num1.put("8",0);num1.put("9",0);
                    res2.add(num1);
                    for (Map<String, Object> re : res) {
                        String stationid = (String) re.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res10) {
                            String quYuId = (String) quYu.get("stationid");
                            if (stationid.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        if (found){
                            HashMap<String, Object> map = new HashMap<>();
                            String quYuId = (String) re.get("stationid");
                            Double quYuLongitude = (Double) re.get("longitude");
                            Double quYuLatitude = (Double) re.get("latitude");
                            String quYuStationname = (String) re.get("stationname");
                            String quYuCounty = (String) re.get("cnty");
                            map.put("stationid", quYuId);
                            map.put("longitude", quYuLongitude);
                            map.put("latitude", quYuLatitude);
                            map.put("stationname", quYuStationname);
                            map.put("cnty", quYuCounty);
                            map.put("value", 0.0);
                            res1.add(map);
                        }else {
                            HashMap<String, Object> map = new HashMap<>();
                            String quYuId = (String) re.get("stationid");
                            Double quYuLongitude = (Double) re.get("longitude");
                            Double quYuLatitude = (Double) re.get("latitude");
                            String quYuStationname = (String) re.get("stationname");
                            String quYuCounty = (String) re.get("cnty");
                            map.put("stationid", quYuId);
                            map.put("longitude", quYuLongitude);
                            map.put("latitude", quYuLatitude);
                            map.put("stationname", quYuStationname);
                            map.put("cnty", quYuCounty);
                            map.put("value", -100.0);
                            res1.add(map);
                        }
                    }
                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0;int tu5=0;int tu6=0;
                    int tu7=0;int tu8=0;int tu9=0;
                    for (Map<String, Object> tu : res1) {
                        int windd = WebCtrlData.FengSuToFengJi((Double) tu.get("value"));
                        if (windd  < 6 ) {
                            tu1++;
                        } else if (windd == 6) {
                            tu2++;
                        } else if (windd == 7) {
                            tu3++;
                        } else if (windd == 8) {
                            tu4++;
                        } else if (windd == 9) {
                            tu5++;
                        } else if (windd == 10) {
                            tu6++;
                        } else if (windd == 11) {
                            tu7++;
                        } else if (windd == 12) {
                            tu8++;
                        } else if (windd == 100){
                           continue;
                        }else {
                        tu9++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4);num.put("5", tu5);num.put("6", tu6);
                    num.put("7", tu7);num.put("8", tu8);num.put("9", tu9);


                    for (Map<String, Object> guoJia : res10) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCounty = (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCounty);
                            newQuYu.put("value", 0.0);
                            res1.add(newQuYu);
                        }
                    }
                    int Y = res.size() - res1.size();
                    int N = res1.size();
                    num.put("YES",N);
                    num.put("NO",Y);
                    res2.add(num);
                    for (Map<String, Object> finalA : res) {
                        String guoJiaId = (String) finalA.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) finalA.get("stationid");
                            Double quYuLongitude = (Double) finalA.get("longitude");
                            Double quYuLatitude = (Double) finalA.get("latitude");
                            String quYuStationname = (String) finalA.get("stationname");
                            String quYuCounty = (String) finalA.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCounty);
                            newQuYu.put("value", -100.0);
                            res1.add(newQuYu);
                        }
                    }
                }
                for (Map<String, Object> map1 : res1) {
                    int windd = WebCtrlData.FengSuToFengJi((Double) map1.get("value"));
                    map1.put("windd", windd);
                }
                res1.sort((mapA, mapB) -> {
                    Double valueA = (Double) mapA.get("value");
                    Double valueB = (Double) mapB.get("value");
                    return valueB.compareTo(valueA); // 从大到小排序
                });
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '风速' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列
                // 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                // for (Map<String, Object> row : res1) {
                //     Double rainValue = (Double) row.get("value");
                //     String color = getColorForRainValue(rainValue, rainToColorMap);
                //     row.put("color", color);
                // }
            } else if (type.equals("maxWind")) {
                sql1.append("WITH RankedData AS (select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,win_d_avg_10mi AS instantwindd,win_s_avg_10mi AS windspeed,cnty,  ")
                        .append("ROW_NUMBER() OVER (PARTITION BY station_id_c ORDER BY win_s_avg_10mi DESC) AS rn ")
                        .append("from msg_other_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + guoJiatime1 + "' and '" + guoJiatime + "' ")
                        .append("and station_id_c like '5%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and win_s_avg_10mi <> '-65535') ")
                        .append("SELECT stationid,longitude,latitude,stationname,instantwindd,windspeed AS value,cnty ")
                        .append("FROM RankedData ")
                        .append("WHERE rn = 1 ")
                        .append("ORDER BY windspeed DESC ");
                res7 = comDisplayService.getMhInfo2(sql1.toString());
                sql7.append("WITH RankedData AS (select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,win_d_avg_10mi AS instantwindd,win_s_avg_10mi AS windspeed,cnty,  ")
                        .append("ROW_NUMBER() OVER (PARTITION BY station_id_c ORDER BY win_s_avg_10mi DESC) AS rn ")
                        .append("from msg_other_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + quYutime1 + "' and '" + quYutime + "' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and win_s_avg_10mi <> '-65535') ")
                        .append("SELECT stationid,longitude,latitude,stationname,instantwindd,windspeed AS value,cnty ")
                        .append("FROM RankedData ")
                        .append("WHERE rn = 1 ")
                        .append("ORDER BY windspeed DESC ");
                res6 = comDisplayService.getMhInfo2(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                if (res1.isEmpty()) {
                    int Y = res.size() - res10.size();
                    int N = res10.size();
                    HashMap<String, Object>  num1 = new HashMap<>();//存储正常异常站点数量
                    num1.put("YES",N);num1.put("NO",Y);num1.put("1",0);//存储图例对应个数
                    num1.put("2",0);num1.put("3",0);num1.put("4",0);
                    num1.put("5",0);num1.put("6",0);num1.put("7",0);
                    num1.put("8",0);num1.put("9",0);
                    res2.add(num1);
                    for (Map<String, Object> re : res) {
                        String stationid = (String) re.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res10) {
                            String quYuId = (String) quYu.get("stationid");
                            if (stationid.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        if (found){
                            HashMap<String, Object> map = new HashMap<>();
                            String quYuId = (String) re.get("stationid");
                            Double quYuLongitude = (Double) re.get("longitude");
                            Double quYuLatitude = (Double) re.get("latitude");
                            String quYuStationname = (String) re.get("stationname");
                            String quYuCounty= (String) re.get("cnty");
                            map.put("stationid", quYuId);
                            map.put("longitude", quYuLongitude);
                            map.put("latitude", quYuLatitude);
                            map.put("stationname", quYuStationname);
                            map.put("cnty", quYuCounty);
                            map.put("value", 0.0);
                            res1.add(map);
                        }else {
                            HashMap<String, Object> map = new HashMap<>();
                            String quYuId = (String) re.get("stationid");
                            Double quYuLongitude = (Double) re.get("longitude");
                            Double quYuLatitude = (Double) re.get("latitude");
                            String quYuStationname = (String) re.get("stationname");
                            String quYuCounty= (String) re.get("cnty");
                            map.put("stationid", quYuId);
                            map.put("longitude", quYuLongitude);
                            map.put("latitude", quYuLatitude);
                            map.put("stationname", quYuStationname);
                            map.put("cnty", quYuCounty);
                            map.put("value", -100.0);
                            res1.add(map);
                        }
                    }
                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0;int tu5=0;int tu6=0;
                    int tu7=0;int tu8=0;int tu9=0;
                    for (Map<String, Object> tu : res1) {
                        int windd = WebCtrlData.FengSuToFengJi((Double) tu.get("value"));
                        if (windd  < 6) {
                            tu1++;
                        } else if (windd == 6) {
                            tu2++;
                        } else if (windd == 7) {
                            tu3++;
                        } else if (windd == 8) {
                            tu4++;
                        } else if (windd == 9) {
                            tu5++;
                        } else if (windd == 10) {
                            tu6++;
                        } else if (windd == 11) {
                            tu7++;
                        } else if (windd == 12) {
                            tu8++;
                        }else if (windd == 100){
                           continue;
                        }else {
                            tu9++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4);num.put("5", tu5);num.put("6", tu6);
                    num.put("7", tu7);num.put("8", tu8);num.put("9", tu9);

                    for (Map<String, Object> guoJia : res10) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCounty= (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCounty);
                            newQuYu.put("value", 0.0);
                            res1.add(newQuYu);
                        }
                    }
                    int Y = res.size() - res1.size();
                    int N = res1.size();
                    num.put("YES",N);
                    num.put("NO",Y);
                    res2.add(num);
                    for (Map<String, Object> finalA : res) {
                        String guoJiaId = (String) finalA.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) finalA.get("stationid");
                            Double quYuLongitude = (Double) finalA.get("longitude");
                            Double quYuLatitude = (Double) finalA.get("latitude");
                            String quYuStationname = (String) finalA.get("stationname");
                            String quYuCounty= (String) finalA.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCounty);
                            newQuYu.put("value", -100.0);
                            res1.add(newQuYu);
                        }
                    }
                }
                for (Map<String, Object> map1 : res1) {
                    int windd = WebCtrlData.FengSuToFengJi((Double) map1.get("value"));
                    map1.put("windd", windd);
                }
                res1.sort((mapA, mapB) -> {
                    Double valueA = (Double) mapA.get("value");
                    Double valueB = (Double) mapB.get("value");
                    return valueB.compareTo(valueA); // 从大到小排序
                });
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '风速' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }

                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列
// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                // for (Map<String, Object> row : res1) {
                //     Double rainValue = (Double) row.get("value");
                //     String color = getColorForRainValue(rainValue, rainToColorMap);
                //     row.put("color", color);
                // }
            } else if (type.equals("rain")) {
                sql1.append("select stationid,longitude,latitude,stationname,rain AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime  = '" + endTime + "' ")
                        .append("and rain <> '-65535' ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo(sql1.toString());
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                for (Map<String, Object> row : res1) {
                    Double rainValue = (Double) row.get("value");
                    String color = getColorForRainValue(rainValue, rainToColorMap);
                    row.put("color", color);
                }

            } else if (type.equals("press")) {
                sql1.append("select stationid,longitude,latitude,stationname,stationpress AS value ")
                        .append("from msgmediumsmallscale ")
                        .append("where stationid in (" + result + ") ")
                        .append("and observtime  = '" + endTime + "' ")
                        .append("and stationpress <> '-65535' ")
                        .append("ORDER BY value DESC ");
                res1 = comDisplayService.getMhInfo(sql1.toString());
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '气压' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                for (Map<String, Object> row : res1) {
                    Double rainValue = (Double) row.get("value");
                    String color = getColorForRainValue(rainValue, rainToColorMap);
                    row.put("color", color);
                }
            } else if (type.equals("10")) {
                instance.setTime(guoJR);
                instance.add(Calendar.MINUTE, -10);
                // 获取减去 10 分钟后的时间
                Date newDate10 = instance.getTime();
                // 格式化新的时间为字符串
                String guoJiatime10 = sim.format(newDate10);

                instance.setTime(quYR);
                instance.add(Calendar.MINUTE, -10);
                // 获取减去 10 分钟后的时间
                Date newDate11 = instance.getTime();
                // 格式化新的时间为字符串
                String quYutime11 = sim.format(newDate11);
                sql1.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + guoJiatime10 + "' and '" + guoJiatime + "' ")
                        .append("and station_id_c like '5%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res7 = comDisplayService.getMhInfo(sql1.toString());
                sql7.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + quYutime11 + "' and '" + quYutime + "' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res6 = comDisplayService.getMhInfo(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                int Y = res.size() - res1.size();
                int N = res1.size();
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                num.put("YES",N);
                num.put("NO",Y);
                res2.add(num);
                if (res1.isEmpty()) {
                    for (Map<String, Object> guoJia : res) {
                        String quYuId = (String) guoJia.get("stationid");
                        Double quYuLongitude = (Double) guoJia.get("longitude");
                        Double quYuLatitude = (Double) guoJia.get("latitude");
                        String quYuStationname = (String) guoJia.get("stationname");
                        String quYuCnty = (String) guoJia.get("cnty");

                        guoJia.put("stationid", quYuId);
                        guoJia.put("longitude", quYuLongitude);
                        guoJia.put("latitude", quYuLatitude);
                        guoJia.put("stationname", quYuStationname);
                        guoJia.put("cnty", quYuCnty);
                        guoJia.put("value", null);
                        res1.add(guoJia);  // 将数据添加到 res1
                    }
                    num.put("1",0);//存储图例对应个数
                    num.put("2",0);num.put("3",0);num.put("4",0);
                    num.put("5",0);num.put("6",0);num.put("7",0);
                    res2.add(num);

                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0;int tu5=0;int tu6=0;int tu7=0;
                    for (Map<String, Object> tu : res1) {
                        Double value = (Double) tu.get("value");
                        if(value < 0.3){
                            tu1++;
                        } else if (value >= 0.3 && value < 6.1) {
                            tu2++;
                        } else if (value >= 6.1 && value < 12.1) {
                            tu3++;
                        } else if (value >= 12.1 && value < 24.1) {
                            tu4++;
                        }else if (value >= 24.1 && value < 48.1) {
                            tu5++;
                        }else if (value >= 48.1 && value <= 96.1) {
                            tu6++;
                        } else  {
                            tu7++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4);num.put("5", tu5);num.put("6", tu6);num.put("7", tu7);
                    res2.add(num);
                    for (Map<String, Object> guoJia : res) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }

                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCnty = (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCnty);
                            newQuYu.put("value", null);

                            res1.add(newQuYu);
                        }
                    }
                }
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                // for (Map<String, Object> row : res1) {
                //     Double rainValue = (Double) row.get("value");
                //     String color = getColorForRainValue(rainValue, rainToColorMap);
                //     row.put("color", color);
                // }
            } else if (type.equals("60")) {
                instance.setTime(guoJR);
                instance.add(Calendar.MINUTE, -60);
                // 获取减去 10 分钟后的时间
                Date newDate60 = instance.getTime();
                // 格式化新的时间为字符串
                String guoJiatime60 = sim.format(newDate60);

                instance.setTime(quYR);
                instance.add(Calendar.MINUTE, -60);
                // 获取减去 10 分钟后的时间
                Date newDate61 = instance.getTime();
                // 格式化新的时间为字符串
                String quYutime60 = sim.format(newDate61);
                sql1.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + guoJiatime60 + "' and '" + guoJiatime + "' ")
                        .append("and station_id_c like '5%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res7 = comDisplayService.getMhInfo(sql1.toString());
                sql7.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + quYutime60 + "' and '" + quYutime + "' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res6 = comDisplayService.getMhInfo(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                int Y = res.size() - res1.size();
                int N = res1.size();
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                num.put("YES",N);
                num.put("NO",Y);
                res2.add(num);
                if (res1.isEmpty()) {
                    for (Map<String, Object> guoJia : res) {
                        String quYuId = (String) guoJia.get("stationid");
                        Double quYuLongitude = (Double) guoJia.get("longitude");
                        Double quYuLatitude = (Double) guoJia.get("latitude");
                        String quYuStationname = (String) guoJia.get("stationname");
                        String quYuCnty = (String) guoJia.get("cnty");

                        guoJia.put("stationid", quYuId);
                        guoJia.put("longitude", quYuLongitude);
                        guoJia.put("latitude", quYuLatitude);
                        guoJia.put("stationname", quYuStationname);
                        guoJia.put("cnty", quYuCnty);
                        guoJia.put("value", null);
                        res1.add(guoJia);  // 将数据添加到 res1
                    }
                    num.put("1",0);//存储图例对应个数
                    num.put("2",0);num.put("3",0);num.put("4",0);
                    num.put("5",0);num.put("6",0);num.put("7",0);
                    res2.add(num);

                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0;int tu5=0;int tu6=0;int tu7=0;
                    for (Map<String, Object> tu : res1) {
                        Double value = (Double) tu.get("value");
                        if(value < 0.3){
                            tu1++;
                        } else if (value >= 0.3 && value < 6.1) {
                            tu2++;
                        } else if (value >= 6.1 && value < 12.1) {
                            tu3++;
                        } else if (value >= 12.1 && value < 24.1) {
                            tu4++;
                        }else if (value >= 24.1 && value < 48.1) {
                            tu5++;
                        }else if (value >= 48.1 && value <= 96.1) {
                            tu6++;
                        } else  {
                            tu7++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4);num.put("5", tu5);num.put("6", tu6);num.put("7", tu7);
                    res2.add(num);
                    for (Map<String, Object> guoJia : res) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCnty = (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCnty);
                            newQuYu.put("value", null);

                            res1.add(newQuYu);
                        }
                    }
                }
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                // for (Map<String, Object> row : res1) {
                //     Double rainValue = (Double) row.get("value");
                //     String color = getColorForRainValue(rainValue, rainToColorMap);
                //     row.put("color", color);
                // }
            } else if (type.equals("120")) {
                instance.setTime(guoJR);
                instance.add(Calendar.MINUTE, -120);
                // 获取减去 10 分钟后的时间
                Date newDate120 = instance.getTime();
                // 格式化新的时间为字符串
                String guoJiatime120 = sim.format(newDate120);

                instance.setTime(quYR);
                instance.add(Calendar.MINUTE, -120);
                // 获取减去 10 分钟后的时间
                Date newDate121 = instance.getTime();
                // 格式化新的时间为字符串
                String quYutime120 = sim.format(newDate121);
                sql1.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + guoJiatime120 + "' and '" + guoJiatime + "' ")
                        .append("and station_id_c like '5%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res7 = comDisplayService.getMhInfo(sql1.toString());
                sql7.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + quYutime120 + "' and '" + quYutime + "' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res6 = comDisplayService.getMhInfo(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                int Y = res.size() - res1.size();
                int N = res1.size();
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                num.put("YES",N);
                num.put("NO",Y);
                res2.add(num);
                if (res1.isEmpty()) {
                    for (Map<String, Object> guoJia : res) {
                        String quYuId = (String) guoJia.get("stationid");
                        Double quYuLongitude = (Double) guoJia.get("longitude");
                        Double quYuLatitude = (Double) guoJia.get("latitude");
                        String quYuStationname = (String) guoJia.get("stationname");
                        String quYuCnty = (String) guoJia.get("cnty");

                        guoJia.put("stationid", quYuId);
                        guoJia.put("longitude", quYuLongitude);
                        guoJia.put("latitude", quYuLatitude);
                        guoJia.put("stationname", quYuStationname);
                        guoJia.put("cnty", quYuCnty);
                        guoJia.put("value", null);
                        res1.add(guoJia);  // 将数据添加到 res1
                    }
                    num.put("1",0);//存储图例对应个数
                    num.put("2",0);num.put("3",0);num.put("4",0);
                    num.put("5",0);num.put("6",0);num.put("7",0);
                    res2.add(num);

                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0;int tu5=0;int tu6=0;int tu7=0;
                    for (Map<String, Object> tu : res1) {
                        Double value = (Double) tu.get("value");
                        if(value < 0.3){
                            tu1++;
                        } else if (value >= 0.3 && value < 6.1) {
                            tu2++;
                        } else if (value >= 6.1 && value < 12.1) {
                            tu3++;
                        } else if (value >= 12.1 && value < 24.1) {
                            tu4++;
                        }else if (value >= 24.1 && value < 48.1) {
                            tu5++;
                        }else if (value >= 48.1 && value <= 96.1) {
                            tu6++;
                        } else  {
                            tu7++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4);num.put("5", tu5);num.put("6", tu6);num.put("7", tu7);
                    res2.add(num);
                    for (Map<String, Object> guoJia : res) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCnty = (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCnty);
                            newQuYu.put("value", null);

                            res1.add(newQuYu);
                        }
                    }
                }
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                // for (Map<String, Object> row : res1) {
                //     Double rainValue = (Double) row.get("value");
                //     String color = getColorForRainValue(rainValue, rainToColorMap);
                //     row.put("color", color);
                // }
            } else if (type.equals("3h")) {
                instance.setTime(guoJR);
                instance.add(Calendar.MINUTE, -180);
                // 获取减去 10 分钟后的时间
                Date newDate180 = instance.getTime();
                // 格式化新的时间为字符串
                String guoJiatime180 = sim.format(newDate180);

                instance.setTime(quYR);
                instance.add(Calendar.MINUTE, -180);
                // 获取减去 10 分钟后的时间
                Date newDate181 = instance.getTime();
                // 格式化新的时间为字符串
                String quYutime180 = sim.format(newDate181);
                sql1.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + guoJiatime180 + "' and '" + guoJiatime + "' ")
                        .append("and station_id_c like '5%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res7 = comDisplayService.getMhInfo(sql1.toString());
                sql7.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + quYutime180 + "' and '" + quYutime + "' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res6 = comDisplayService.getMhInfo(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                int Y = res.size() - res1.size();
                int N = res1.size();
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                num.put("YES",N);
                num.put("NO",Y);
                res2.add(num);
                if (res1.isEmpty()) {
                    for (Map<String, Object> guoJia : res) {
                        String quYuId = (String) guoJia.get("stationid");
                        Double quYuLongitude = (Double) guoJia.get("longitude");
                        Double quYuLatitude = (Double) guoJia.get("latitude");
                        String quYuStationname = (String) guoJia.get("stationname");
                        String quYuCnty = (String) guoJia.get("cnty");

                        guoJia.put("stationid", quYuId);
                        guoJia.put("longitude", quYuLongitude);
                        guoJia.put("latitude", quYuLatitude);
                        guoJia.put("stationname", quYuStationname);
                        guoJia.put("cnty", quYuCnty);
                        guoJia.put("value", null);
                        res1.add(guoJia);  // 将数据添加到 res1
                    }
                    num.put("1",0);//存储图例对应个数
                    num.put("2",0);num.put("3",0);num.put("4",0);
                    num.put("5",0);num.put("6",0);num.put("7",0);
                    res2.add(num);

                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0;int tu5=0;int tu6=0;int tu7=0;
                    for (Map<String, Object> tu : res1) {
                        Double value = (Double) tu.get("value");
                        if(value < 0.3){
                            tu1++;
                        } else if (value >= 0.3 && value < 6.1) {
                            tu2++;
                        } else if (value >= 6.1 && value < 12.1) {
                            tu3++;
                        } else if (value >= 12.1 && value < 24.1) {
                            tu4++;
                        }else if (value >= 24.1 && value < 48.1) {
                            tu5++;
                        }else if (value >= 48.1 && value <= 96.1) {
                            tu6++;
                        } else  {
                            tu7++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4);num.put("5", tu5);num.put("6", tu6);num.put("7", tu7);
                    res2.add(num);
                    for (Map<String, Object> guoJia : res) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCnty = (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCnty);
                            newQuYu.put("value", null);

                            res1.add(newQuYu);
                        }
                    }
                }
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                // for (Map<String, Object> row : res1) {
                //     Double rainValue = (Double) row.get("value");
                //     String color = getColorForRainValue(rainValue, rainToColorMap);
                //     row.put("color", color);
                // }
            } else if (type.equals("6h")) {
                instance.setTime(guoJR);
                instance.add(Calendar.MINUTE, -360);
                // 获取减去 10 分钟后的时间
                Date newDate360 = instance.getTime();
                // 格式化新的时间为字符串
                String guoJiatime360 = sim.format(newDate360);
                instance.setTime(quYR);
                instance.add(Calendar.MINUTE, -360);
                // 获取减去 10 分钟后的时间
                Date newDate361 = instance.getTime();
                // 格式化新的时间为字符串
                String quYutime360 = sim.format(newDate361);
                sql1.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + guoJiatime360 + "' and '" + guoJiatime + "' ")
                        .append("and station_id_c like '5%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res7 = comDisplayService.getMhInfo(sql1.toString());
                sql7.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + quYutime360 + "' and '" + quYutime + "' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res6 = comDisplayService.getMhInfo(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                int Y = res.size() - res1.size();
                int N = res1.size();
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                num.put("YES",N);
                num.put("NO",Y);
                res2.add(num);
                if (res1.isEmpty()) {
                    for (Map<String, Object> guoJia : res) {
                        String quYuId = (String) guoJia.get("stationid");
                        Double quYuLongitude = (Double) guoJia.get("longitude");
                        Double quYuLatitude = (Double) guoJia.get("latitude");
                        String quYuStationname = (String) guoJia.get("stationname");
                        String quYuCnty = (String) guoJia.get("cnty");

                        guoJia.put("stationid", quYuId);
                        guoJia.put("longitude", quYuLongitude);
                        guoJia.put("latitude", quYuLatitude);
                        guoJia.put("stationname", quYuStationname);
                        guoJia.put("cnty", quYuCnty);
                        guoJia.put("value", null);
                        res1.add(guoJia);  // 将数据添加到 res1
                    }
                    num.put("1",0);//存储图例对应个数
                    num.put("2",0);num.put("3",0);num.put("4",0);
                    num.put("5",0);num.put("6",0);num.put("7",0);
                    res2.add(num);

                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0;int tu5=0;int tu6=0;int tu7=0;
                    for (Map<String, Object> tu : res1) {
                        Double value = (Double) tu.get("value");
                        if(value < 0.3){
                            tu1++;
                        } else if (value >= 0.3 && value < 6.1) {
                            tu2++;
                        } else if (value >= 6.1 && value < 12.1) {
                            tu3++;
                        } else if (value >= 12.1 && value < 24.1) {
                            tu4++;
                        }else if (value >= 24.1 && value < 48.1) {
                            tu5++;
                        }else if (value >= 48.1 && value <= 96.1) {
                            tu6++;
                        } else  {
                            tu7++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4);num.put("5", tu5);num.put("6", tu6);num.put("7", tu7);
                    res2.add(num);
                    for (Map<String, Object> guoJia : res) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCnty = (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCnty);
                            newQuYu.put("value", null);

                            res1.add(newQuYu);
                        }
                    }
                }
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '6小时雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                // for (Map<String, Object> row : res1) {
                //     Double rainValue = (Double) row.get("value");
                //     String color = getColorForRainValue(rainValue, rainToColorMap);
                //     row.put("color", color);
                // }
            } else if (type.equals("12h")) {
                instance.setTime(guoJR);
                instance.add(Calendar.MINUTE, -720);
                // 获取减去 10 分钟后的时间
                Date newDate720 = instance.getTime();
                // 格式化新的时间为字符串
                String guoJiatime720 = sim.format(newDate720);

                instance.setTime(quYR);
                instance.add(Calendar.MINUTE, -720);
                // 获取减去 10 分钟后的时间
                Date newDate721 = instance.getTime();
                // 格式化新的时间为字符串
                String quYutime720 = sim.format(newDate721);
                sql1.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + guoJiatime720 + "' and '" + guoJiatime + "' ")
                        .append("and station_id_c like '5%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res7 = comDisplayService.getMhInfo(sql1.toString());
                sql7.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + quYutime720 + "' and '" + quYutime + "' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res6 = comDisplayService.getMhInfo(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                int Y = res.size() - res1.size();
                int N = res1.size();
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                num.put("YES",N);
                num.put("NO",Y);
                res2.add(num);
                if (res1.isEmpty()) {
                    for (Map<String, Object> guoJia : res) {
                        String quYuId = (String) guoJia.get("stationid");
                        Double quYuLongitude = (Double) guoJia.get("longitude");
                        Double quYuLatitude = (Double) guoJia.get("latitude");
                        String quYuStationname = (String) guoJia.get("stationname");
                        String quYuCnty = (String) guoJia.get("cnty");

                        guoJia.put("stationid", quYuId);
                        guoJia.put("longitude", quYuLongitude);
                        guoJia.put("latitude", quYuLatitude);
                        guoJia.put("stationname", quYuStationname);
                        guoJia.put("cnty", quYuCnty);
                        guoJia.put("value", null);
                        res1.add(guoJia);  // 将数据添加到 res1
                    }
                    num.put("1",0);//存储图例对应个数
                    num.put("2",0);num.put("3",0);num.put("4",0);
                    num.put("5",0);num.put("6",0);num.put("7",0);
                    res2.add(num);

                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0;int tu5=0;int tu6=0;int tu7=0;
                    for (Map<String, Object> tu : res1) {
                        Double value = (Double) tu.get("value");
                        if( value < 0.3){
                            tu1++;
                        } else if (value >= 0.3 && value < 6.1) {
                            tu2++;
                        } else if (value >= 6.1 && value < 12.1) {
                            tu3++;
                        } else if (value >= 12.1 && value < 24.1) {
                            tu4++;
                        }else if (value >= 24.1 && value < 48.1) {
                            tu5++;
                        }else if (value >= 48.1 && value <= 96.1) {
                            tu6++;
                        } else  {
                            tu7++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4);num.put("5", tu5);num.put("6", tu6);num.put("7", tu7);
                    res2.add(num);
                    for (Map<String, Object> guoJia : res) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCnty = (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCnty);
                            newQuYu.put("value", null);

                            res1.add(newQuYu);
                        }
                    }
                }
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '12小时雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                // for (Map<String, Object> row : res1) {
                //     Double rainValue = (Double) row.get("value");
                //     String color = getColorForRainValue(rainValue, rainToColorMap);
                //     row.put("color", color);
                // }
            }else if (type.equals("24h")) {
                instance.setTime(guoJR);
                instance.add(Calendar.MINUTE, -1440);
                // 获取减去 10 分钟后的时间
                Date newDate1440 = instance.getTime();
                // 格式化新的时间为字符串
                String guoJiatime1440 = sim.format(newDate1440);
                instance.setTime(quYR);
                instance.add(Calendar.MINUTE, -1440);
                // 获取减去 10 分钟后的时间
                Date newDate1441 = instance.getTime();
                // 格式化新的时间为字符串
                String quYutime1440 = sim.format(newDate1441);
                sql1.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + guoJiatime1440 + "' and '" + guoJiatime + "' ")
                        .append("and station_id_c like '5%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res7 = comDisplayService.getMhInfo(sql1.toString());
                sql7.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + quYutime1440 + "' and '" + quYutime + "' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                res6 = comDisplayService.getMhInfo(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                int Y = res.size() - res1.size();
                int N = res1.size();
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                num.put("YES",N);
                num.put("NO",Y);
                res2.add(num);
                if (res1.isEmpty()) {
                    for (Map<String, Object> guoJia : res) {
                        String quYuId = (String) guoJia.get("stationid");
                        Double quYuLongitude = (Double) guoJia.get("longitude");
                        Double quYuLatitude = (Double) guoJia.get("latitude");
                        String quYuStationname = (String) guoJia.get("stationname");
                        String quYuCnty = (String) guoJia.get("cnty");

                        guoJia.put("stationid", quYuId);
                        guoJia.put("longitude", quYuLongitude);
                        guoJia.put("latitude", quYuLatitude);
                        guoJia.put("stationname", quYuStationname);
                        guoJia.put("cnty", quYuCnty);
                        guoJia.put("value", null);
                        res1.add(guoJia);  // 将数据添加到 res1
                    }
                    num.put("1",0);//存储图例对应个数
                    num.put("2",0);num.put("3",0);num.put("4",0);
                    num.put("5",0);num.put("6",0);num.put("7",0);
                    res2.add(num);

                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0;int tu5=0;int tu6=0;int tu7=0;
                    for (Map<String, Object> tu : res1) {
                        Double value = (Double) tu.get("value");
                        if(value < 0.3){
                            tu1++;
                        } else if (value >= 0.3 && value < 6.1) {
                            tu2++;
                        } else if (value >= 6.1 && value < 12.1) {
                            tu3++;
                        } else if (value >= 12.1 && value < 24.1) {
                            tu4++;
                        }else if (value >= 24.1 && value < 48.1) {
                            tu5++;
                        }else if (value >= 48.1 && value <= 96.1) {
                            tu6++;
                        } else  {
                            tu7++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4);num.put("5", tu5);num.put("6", tu6);num.put("7", tu7);
                    res2.add(num);
                    for (Map<String, Object> guoJia : res) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCnty = (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCnty);
                            newQuYu.put("value", null);

                            res1.add(newQuYu);
                        }
                    }
                }
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '24小时雨量' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue =(Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                // for (Map<String, Object> row : res1) {
                //     Double rainValue = (Double) row.get("value");
                //     String color = getColorForRainValue(rainValue, rainToColorMap);
                //     row.put("color", color);
                // }

            } else if (type.equals("1Vis")) {
                    sql1.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,MAX(vis_hor_1mi) AS value,cnty ")
                            .append("from msg_other_minute ")
                            .append("where station_id_c in (" + result + ") ")
                            .append("and datetime between '" + guoJiatime1 + "' and '" + guoJiatime + "' ")
                            .append("and station_id_c like '5%' ")
                            .append("and vis_hor_1mi <> '-65535'")
                            .append("AND city like '%伊犁%' ")
                            .append("GROUP BY station_id_c, lon, lat, station_name,cnty ")
                            .append("ORDER BY value DESC ");
                    res7 = comDisplayService.getMhInfo(sql1.toString());
                    sql7.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,MAX(vis_hor_1mi) AS value,cnty ")
                        .append("from msg_other_minute ")
                        .append("where station_id_c in (" + result + ") ")
                            .append("and datetime between '" + quYutime1 + "' and '" + quYutime + "' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("and vis_hor_1mi <> '-65535'")
                        .append("AND city like '%伊犁%' ")
                        .append("GROUP BY station_id_c, lon, lat, station_name,cnty ")
                        .append("ORDER BY value DESC ");
                    res6 = comDisplayService.getMhInfo(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                if (res1.isEmpty()) {
                    int Y = res.size() - res10.size();
                    int N = res10.size();
                    HashMap<String, Object>  num1 = new HashMap<>();//存储正常异常站点数量
                    num1.put("YES",N);num1.put("NO",Y);num1.put("1",0);//存储图例对应个数
                    num1.put("2",0);num1.put("3",0);num1.put("4",0);num1.put("5",0);
                    res2.add(num1);
                    for (Map<String, Object> re : res) {
                        String stationid = (String) re.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res10) {
                            String quYuId = (String) quYu.get("stationid");
                            if (stationid.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        if (found){
                            HashMap<String, Object> map = new HashMap<>();
                            String quYuId = (String) re.get("stationid");
                            Double quYuLongitude = (Double) re.get("longitude");
                            Double quYuLatitude = (Double) re.get("latitude");
                            String quYuStationname = (String) re.get("stationname");
                            String quYuCnty = (String) re.get("cnty");
                            map.put("stationid", quYuId);
                            map.put("longitude", quYuLongitude);
                            map.put("latitude", quYuLatitude);
                            map.put("stationname", quYuStationname);
                            map.put("cnty", quYuCnty);
                            map.put("value", "Y");
                            res1.add(map);
                        }else {
                            HashMap<String, Object> map = new HashMap<>();
                            String quYuId = (String) re.get("stationid");
                            Double quYuLongitude = (Double) re.get("longitude");
                            Double quYuLatitude = (Double) re.get("latitude");
                            String quYuStationname = (String) re.get("stationname");
                            String quYuCnty = (String) re.get("cnty");
                            map.put("stationid", quYuId);
                            map.put("longitude", quYuLongitude);
                            map.put("latitude", quYuLatitude);
                            map.put("stationname", quYuStationname);
                            map.put("cnty", quYuCnty);
                            map.put("value", "N");
                            res1.add(map);
                        }
                    }
                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0; int tu5=0;
                    for (Map<String, Object> tu : res1) {
                        Double value = (Double) tu.get("value");
                        if (value  <= 50) {
                            tu1++;
                        } else if (value > 50 && value <= 200) {
                            tu2++;
                        } else if (value > 200 && value <= 500) {
                            tu3++;
                        }else if (value > 500 && value <= 1000){
                            tu4++;
                        }else {
                            tu5++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4); num.put("5", tu5);
                    for (Map<String, Object> guoJia : res10) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCnty = (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCnty);
                            newQuYu.put("value", "Y");
                            res1.add(newQuYu);
                        }
                    }
                    int Y = res.size() - res1.size();
                    int N = res1.size();
                    num.put("YES",N);
                    num.put("NO",Y);
                    res2.add(num);
                    for (Map<String, Object> finalA : res) {
                        String guoJiaId = (String) finalA.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) finalA.get("stationid");
                            Double quYuLongitude = (Double) finalA.get("longitude");
                            Double quYuLatitude = (Double) finalA.get("latitude");
                            String quYuStationname = (String) finalA.get("stationname");
                            String quYuCnty = (String) finalA.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCnty);
                            newQuYu.put("value", "N");
                            res1.add(newQuYu);
                        }
                    }
                }
                    sql2.append("select elementvalue,elementcolor ")
                            .append("from contour_setting ")
                            .append("where elementtype = '能见度' ")
                            .append("ORDER BY  elementvalue  ASC");
                    getcolor = comDisplayService.getcolor(sql2.toString());
                    for (Map<String, Object> map : getcolor) {
                        String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                        map.put("16color", colorValue);

                    }
                    Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                    for (Map<String, Object> row : getcolor) {
                        Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                        Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                        rainToColorMap.put(rainValue, colorValue);
                    }
                    // for (Map<String, Object> row : res1) {
                    //     Double rainValue = (Double) row.get("value");
                    //     String color = getColorForRainValue(rainValue, rainToColorMap);
                    //     row.put("color", color);
                    // }
            }else if (type.equals("10Vis")) {
                sql1.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,MAX(vis_hor_10mi) AS value,cnty ")
                        .append("from msg_other_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + guoJiatime1 + "' and '" + guoJiatime + "' ")
                        .append("and vis_hor_10mi <> '-65535'")
                        .append("and station_id_c like '5%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("GROUP BY station_id_c, lon, lat, station_name,cnty ")
                        .append("ORDER BY value DESC  ");
                res7 = comDisplayService.getMhInfo(sql1.toString());
                sql7.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,MAX(vis_hor_10mi) AS value,cnty ")
                        .append("from msg_other_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + quYutime1 + "' and '" + quYutime + "' ")
                        .append("and vis_hor_10mi <> '-65535' ")
                        .append("and station_id_c like 'Y%' ")
                        .append("AND city like '%伊犁%' ")
                        .append("GROUP BY station_id_c, lon, lat, station_name,cnty ")
                        .append("ORDER BY value DESC  ");
                res6 = comDisplayService.getMhInfo(sql7.toString());
                if (res6.size() > 0){
                    res1.addAll(res6);
                }
                if (res7.size() >0){
                    res1.addAll(res7);
                }
                HashMap<String, Object>  num = new HashMap<>();//存储正常异常站点数量
                if (res1.isEmpty()) {
                    int Y = res.size() - res10.size();
                    int N = res10.size();
                    HashMap<String, Object>  num1 = new HashMap<>();//存储正常异常站点数量
                    num1.put("YES",N);num1.put("NO",Y);num1.put("1",0);//存储图例对应个数
                    num1.put("2",0);num1.put("3",0);num1.put("4",0);num1.put("5",0);
                    res2.add(num1);
                    for (Map<String, Object> re : res) {
                        String stationid = (String) re.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res10) {
                            String quYuId = (String) quYu.get("stationid");
                            if (stationid.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        if (found){
                            HashMap<String, Object> map = new HashMap<>();
                            String quYuId = (String) re.get("stationid");
                            Double quYuLongitude = (Double) re.get("longitude");
                            Double quYuLatitude = (Double) re.get("latitude");
                            String quYuStationname = (String) re.get("stationname");
                            String quYuCnty = (String) re.get("cnty");
                            map.put("stationid", quYuId);
                            map.put("longitude", quYuLongitude);
                            map.put("latitude", quYuLatitude);
                            map.put("stationname", quYuStationname);
                            map.put("cnty", quYuCnty);
                            map.put("value", "Y");
                            res1.add(map);
                        }else {
                            HashMap<String, Object> map = new HashMap<>();
                            String quYuId = (String) re.get("stationid");
                            Double quYuLongitude = (Double) re.get("longitude");
                            Double quYuLatitude = (Double) re.get("latitude");
                            String quYuStationname = (String) re.get("stationname");
                            String quYuCnty = (String) re.get("cnty");
                            map.put("stationid", quYuId);
                            map.put("longitude", quYuLongitude);
                            map.put("latitude", quYuLatitude);
                            map.put("stationname", quYuStationname);
                            map.put("cnty", quYuCnty);
                            map.put("value", "N");
                            res1.add(map);
                        }
                    }
                } else {
                    int tu1 =0;int tu2=0;int tu3=0;
                    int tu4=0;int tu5=0;
                    for (Map<String, Object> tu : res1) {
                        Double value = (Double) tu.get("value");
                        if (value  <= 50) {
                            tu1++;
                        } else if (value > 50 && value <= 200) {
                            tu2++;
                        } else if (value > 200 && value <= 500) {
                            tu3++;
                        }else if (value > 500 && value <= 1000){
                            tu4++;
                        }else {
                            tu5++;
                        }
                    }
                    num.put("1", tu1);num.put("2", tu2);num.put("3", tu3);
                    num.put("4", tu4);num.put("5", tu5);
                    for (Map<String, Object> guoJia : res10) {
                        String guoJiaId = (String) guoJia.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) guoJia.get("stationid");
                            Double quYuLongitude = (Double) guoJia.get("longitude");
                            Double quYuLatitude = (Double) guoJia.get("latitude");
                            String quYuStationname = (String) guoJia.get("stationname");
                            String quYuCnty = (String) guoJia.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCnty);
                            newQuYu.put("value", "Y");
                            res1.add(newQuYu);
                        }
                    }
                    int Y = res.size() - res1.size();
                    int N = res1.size();
                    num.put("YES",N);
                    num.put("NO",Y);
                    res2.add(num);
                    for (Map<String, Object> finalA : res) {
                        String guoJiaId = (String) finalA.get("stationid");
                        boolean found = false;
                        for (Map<String, Object> quYu : res1) {
                            String quYuId = (String) quYu.get("stationid");
                            if (guoJiaId.equals(quYuId)) {
                                found = true;
                                break;
                            }
                        }
                        // 如果没有找到匹配的 stationid，添加相应的字段到 guoJia
                        if (!found) {
                            Map<String, Object> newQuYu = new HashMap<>();
                            // 用来保存 quYu 中的相关字段信息
                            String quYuId = (String) finalA.get("stationid");
                            Double quYuLongitude = (Double) finalA.get("longitude");
                            Double quYuLatitude = (Double) finalA.get("latitude");
                            String quYuStationname = (String) finalA.get("stationname");
                            String quYuCnty = (String) finalA.get("cnty");
                            newQuYu.put("stationid", quYuId);
                            newQuYu.put("longitude", quYuLongitude);
                            newQuYu.put("latitude", quYuLatitude);
                            newQuYu.put("stationname", quYuStationname);
                            newQuYu.put("cnty", quYuCnty);
                            newQuYu.put("value", "N");
                            res1.add(newQuYu);
                        }
                    }
                }
                sql2.append("select elementvalue,elementcolor ")
                        .append("from contour_setting ")
                        .append("where elementtype = '能见度' ")
                        .append("ORDER BY  elementvalue  ASC");
                getcolor = comDisplayService.getcolor(sql2.toString());
                for (Map<String, Object> map : getcolor) {
                    String colorValue = decimalToHex((Integer) map.get("elementcolor"));// 对应的颜色值
                    map.put("16color", colorValue);

                }
                Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
                for (Map<String, Object> row : getcolor) {
                    Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                    Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                    rainToColorMap.put(rainValue, colorValue);
                }
                // for (Map<String, Object> row : res1) {
                //     Double rainValue = (Double) row.get("value");
                //     String color = getColorForRainValue(rainValue, rainToColorMap);
                //     row.put("color", color);
                // }
            }
        } catch (Exception e) {
            return Results1.fail(e.getMessage());
        }

        return Results1.success("success", 1, res1,res2);
    }

    @GetMapping("/getProjectInfo")
    @ResponseBody
    public Results getProjectInfo(HttpServletRequest request, Model model) {
        List<Map<String,Object>> res =null;
        try {
            StringBuilder sql = new StringBuilder();
            sql.append("select id,name,overview,latitude,longitude ")
                    .append("from project_info ");
            res = comDisplayService.getProjectInfo(sql.toString());
        } catch (Exception e) {
            return Results.fail(e.getMessage());
        }
        return Results.success("获取重大工程信息", 1, res);


    }

    /**
     * 获取预警信号
     */
    @GetMapping("/getNewWarnInfo")
    @ResponseBody
    public Results getNewWarnInfo(HttpServletRequest request, Model model) {
        String county = request.getParameter("advname");

        String county1 = "";
        switch (county) {
            case "伊犁州直":
                county1 = "伊宁市";
                break;
            case "伊宁市":
                county1 = "伊宁市";
                break;
            default:
                return null;
        }
        String stationId = "";
        switch (county) {
            case "伊犁州直":
                stationId = "51431";
                break;
            case "伊宁市":
                stationId = "51431";
                break;
            default:
                return null;
        }
        try {
            StringBuilder sql = new StringBuilder();
            sql.append("select stationid,longitude,latitude,stationname ")
                    .append("from smallscale_station ")
                    .append("where county = '" + county1 + "'");
            List<Map<String,Object>> res = comDisplayService.getStationInfo(sql.toString());
            System.out.println("res: "+ res);
            // 使用 StringJoiner 来连接结果
            StringJoiner joiner = new StringJoiner(",");

            // 遍历 res 列表，提取每个 stationid，并在添加到 joiner 时加上单引号
            for (Map<String, Object> station : res) {
                String stationId1 = (String) station.get("stationid");
                joiner.add("'" + stationId1 + "'");  // 在每个 stationid 前后加上单引号
            }

            // 最终结果就是你想要的字符串
            String result = joiner.toString();
            StringBuilder sql1 = new StringBuilder();
            sql1.append("select description,city,area,color,defenseguide,CONCAT ( TYPE, '', color ) AS TYPE,")
                    .append("announcedtime ")
                    .append("FROM warn_signal_info ")
                    .append("where area ='" + county1 + "'")
                    .append("ORDER BY announcedtime DESC");
            List<Map<String, Object>> res1 = comDisplayService.getNewWarnInfo(sql1.toString());
            for (Map<String, Object> warnInfo : res1) {
                for (Map<String, Object> stationInfo : res) {
                    if (stationId.equals(stationInfo.get("stationid"))) {
                        warnInfo.put("latitude", stationInfo.get("latitude"));
                        warnInfo.put("longitude", stationInfo.get("longitude"));
                        warnInfo.put("stationName", stationInfo.get("stationname"));
                        break;
                    }

                }
            }
            return Results.success("success", 1, res1);
        } catch (Exception e) {
            return Results.fail(e.getMessage());
        }
    }

/*获取监测预警信息*/
    @GetMapping("/getMonitoringInfoNew")
    @ResponseBody
    public Results getMonitoringInfoNew(HttpServletRequest request, Model model) {
        String county = request.getParameter("advname");
        String county1 = "";
        String county2 = "";
        switch (county){
            case "伊犁州直":
                county1="654000";
                break;
            case "伊犁河谷":
                county1="654000";
                break;
            case "伊宁市":
                county1="654002";
                break;
            case "奎屯市":
                county1="654003";
                break;
            case "霍尔果斯市":
                county1="654004";
                break;
            case "察县":
                county1="654022";
                break;
            case "霍城县":
                county1="654023";
                break;
            case "巩留县":
                county1="654024";
                break;
            case "新源县":
                county1="654025";
                break;
            case "昭苏县":
                county1="654026";
                break;
            case "特克斯县":
                county1="654027";
                break;
            case "尼勒克县":
                county1="654028";
                break;
            default:
                return null;
        }
        switch (county) {
            case "伊犁州直":
                county2 = "'伊宁市','察布查尔锡伯自治县','奎屯市','霍尔果斯市','伊宁县','巩留县','霍城县','新源县','昭苏县','特克斯县','尼勒克县'";
                break;
            case "伊犁河谷":
                county2 = "'伊宁市','察布查尔锡伯自治县','霍尔果斯市','伊宁县','巩留县','霍城县','新源县','昭苏县','特克斯县','尼勒克县'";
                break;
            case "察县":
                county2 = "'察布查尔锡伯自治县'";
                break;
            case "伊宁市":
                county2 = "'伊宁市'";
                break;
            case "奎屯市":
                county2 = "'奎屯市'";
                break;
            case "霍尔果斯市":
                county2 = "'霍尔果斯市'";
                break;
            case "伊宁县":
                county2 = "'伊宁县'";
                break;
            case "巩留县":
                county2 = "'巩留县'";
                break;
            case "霍城县":
                county2 = "'霍城县'";
                break;
            case "新源县":
                county2 = "'新源县'";
                break;
            case "昭苏县":
                county2 = "'昭苏县'";
                break;
            case "特克斯县":
                county2 = "'特克斯县'";
                break;
            case "尼勒克县":
                county2 = "'尼勒克县'";
                break;
            default:
                return null;
        }
        try {
            StringBuilder sql = new StringBuilder();
            sql.append("select stationid,longitude,latitude,stationname ")
                    .append("from smallscale_station ")
                    .append("where county IN (" + county2 + ")");
            List<Map<String, Object>> res = comDisplayService.getStationInfo(sql.toString());
            // 使用 StringJoiner 来连接结果
            StringJoiner joiner = new StringJoiner(",");
            // 遍历 res 列表，提取每个 stationid，并在添加到 joiner 时加上单引号
            for (Map<String, Object> station : res) {
                String stationId1 = (String) station.get("stationid");
                joiner.add("'" + stationId1 + "'");  // 在每个 stationid 前后加上单引号
            }
            // 最终结果就是你想要的字符串
            String result = joiner.toString();

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            // 获取当前时间
            Date date = new Date();
            // // 获取 Calendar 实例并设置当前时间
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            Date time = calendar.getTime();
            String endtime = simpleDateFormat.format(time);
            int[] timeAdjustments = {-10, -60, -180, -360, -720, -1440};
            StringBuilder sql1 = new StringBuilder();

            Map<Integer, Integer> countMap1 = new HashMap<>();
            for (int i = 0; i < timeAdjustments.length; i++) {
                StringBuilder sql2 = new StringBuilder();
                // 调整时间，减去指定的分钟数
                calendar.setTime(date);
                calendar.add(Calendar.MINUTE, timeAdjustments[i]);
                Date date1 = calendar.getTime();
                String startTime = simpleDateFormat.format(date1);
                sql2.append("select station_id_c AS stationid,lon AS longitude,lat AS latitude,station_name AS stationname,SUM(pre) AS value,cnty ")
                        .append("from msg_rain_minute ")
                        .append("where station_id_c in (" + result + ") ")
                        .append("and datetime between '" + startTime + "' and '" + endtime + "' ")
                        .append("AND city like '%伊犁%' ")
                        .append("and pre <> '-65535' ")
                        .append("GROUP BY stationid, longitude, latitude, stationname,cnty ")
                        .append("ORDER BY value DESC ");
                List<Map<String, Object>> res7 = comDisplayService.getMhInfo(sql2.toString());
                int count = 0;
                for (Map<String, Object> map : res7) {
                    Double value = (Double) map.get("value");
                    if (value > 0) {
                        count++;
                        continue;
                    }
                }
                countMap1.put(i + 1 , count);
            }
            sql1.append("select stationid,warningtype,warningtime,monitorvalue,standardbasis,monitorname ")
                    .append("FROM warn_moni_info ")
                    .append("WHERE county = '"+county1+"' ")
                    .append("AND isremoved != '1'");
            List<Map<String, Object>> res1 = comDisplayService.getMonitoringInfoNew(sql1.toString());
            // 初始化一个列表，用于存储最终的统计数据
            List<Map<String, Object>> result1 = new ArrayList<>();

            // 预定义monitorname的顺序
            String[] monitorNames = { "10分钟降水", "60分钟降水", "3小时降水", "6小时降水", "12小时降水","24小时降水","高温", "低温", "大风","能见度"};
            // 遍历每个监测类型
            for (String monitorName : monitorNames) {
                // 创建一个存储当前monitorName统计数据的Map
                Map<String, Integer> countMap = new HashMap<>();
                if (monitorName.equals("10分钟降水")){
                    // 初始化四个颜色对应的计数器
                    countMap.put("红色", 0); // 0 - 红色
                    countMap.put("橙色", 0); // 1 - 橙色
                    countMap.put("黄色", 0); // 2 - 黄色
                    countMap.put("蓝色", 0); // 3 - 蓝色
                    countMap.put("站点数", countMap1.get(1));
                    // 遍历 res1，统计对应monitorname的标准值数量
                    for (Map<String, Object> map : res1) {
                        if (monitorName.equals(map.get("monitorname"))) {
                            String standardBasis = map.get("standardbasis").toString();
                            // double monitorvalue = Double.parseDouble(map.get("monitorvalue").toString());
                            // if (monitorvalue > 0 ){
                            //     countMap.put("站点数", countMap.get("站点数") + 1);
                            // }
                            // 根据standardbasis的值更新countMap
                            if (standardBasis != null) {
                                switch (standardBasis) {
                                    case "0":
                                        countMap.put("红色", countMap.get("红色") + 1);
                                        break;
                                    case "1":
                                        countMap.put("橙色", countMap.get("橙色") + 1);
                                        break;
                                    case "2":
                                        countMap.put("黄色", countMap.get("黄色") + 1);
                                        break;
                                    case "3":
                                        countMap.put("蓝色", countMap.get("蓝色") + 1);
                                        break;
                                }
                            }
                        }
                    }
                }else if (monitorName.equals("60分钟降水")){
                    // 初始化四个颜色对应的计数器
                    countMap.put("红色", 0); // 0 - 红色
                    countMap.put("橙色", 0); // 1 - 橙色
                    countMap.put("黄色", 0); // 2 - 黄色
                    countMap.put("蓝色", 0); // 3 - 蓝色
                    countMap.put("站点数", countMap1.get(2));
                    // 遍历 res1，统计对应monitorname的标准值数量
                    for (Map<String, Object> map : res1) {
                        if (monitorName.equals(map.get("monitorname"))) {
                            String standardBasis = map.get("standardbasis").toString();
                            // double monitorvalue = Double.parseDouble(map.get("monitorvalue").toString());
                            // if (monitorvalue > 0 ){
                            //     countMap.put("站点数", countMap.get("站点数") + 1);
                            // }
                            // 根据standardbasis的值更新countMap
                            if (standardBasis != null) {
                                switch (standardBasis) {
                                    case "0":
                                        countMap.put("红色", countMap.get("红色") + 1);
                                        break;
                                    case "1":
                                        countMap.put("橙色", countMap.get("橙色") + 1);
                                        break;
                                    case "2":
                                        countMap.put("黄色", countMap.get("黄色") + 1);
                                        break;
                                    case "3":
                                        countMap.put("蓝色", countMap.get("蓝色") + 1);
                                        break;
                                }
                            }
                        }
                    }
                } else if (monitorName.equals("3小时降水")){
                    // 初始化四个颜色对应的计数器
                    countMap.put("红色", 0); // 0 - 红色
                    countMap.put("橙色", 0); // 1 - 橙色
                    countMap.put("黄色", 0); // 2 - 黄色
                    countMap.put("蓝色", 0); // 3 - 蓝色
                    countMap.put("站点数", countMap1.get(3));
                    // 遍历 res1，统计对应monitorname的标准值数量
                    for (Map<String, Object> map : res1) {
                        if (monitorName.equals(map.get("monitorname"))) {
                            String standardBasis = map.get("standardbasis").toString();
                            // double monitorvalue = Double.parseDouble(map.get("monitorvalue").toString());
                            // if (monitorvalue > 0 ){
                            //     countMap.put("站点数", countMap.get("站点数") + 1);
                            // }
                            // 根据standardbasis的值更新countMap
                            if (standardBasis != null) {
                                switch (standardBasis) {
                                    case "0":
                                        countMap.put("红色", countMap.get("红色") + 1);
                                        break;
                                    case "1":
                                        countMap.put("橙色", countMap.get("橙色") + 1);
                                        break;
                                    case "2":
                                        countMap.put("黄色", countMap.get("黄色") + 1);
                                        break;
                                    case "3":
                                        countMap.put("蓝色", countMap.get("蓝色") + 1);
                                        break;
                                }
                            }
                        }
                    }
                }else if (monitorName.equals("6小时降水")){
                    // 初始化四个颜色对应的计数器
                    countMap.put("红色", 0); // 0 - 红色
                    countMap.put("橙色", 0); // 1 - 橙色
                    countMap.put("黄色", 0); // 2 - 黄色
                    countMap.put("蓝色", 0); // 3 - 蓝色
                    countMap.put("站点数", countMap1.get(4));
                    // 遍历 res1，统计对应monitorname的标准值数量
                    for (Map<String, Object> map : res1) {
                        if (monitorName.equals(map.get("monitorname"))) {
                            String standardBasis = map.get("standardbasis").toString();
                            // double monitorvalue = Double.parseDouble(map.get("monitorvalue").toString());
                            // if (monitorvalue > 0 ){
                            //     countMap.put("站点数", countMap.get("站点数") + 1);
                            // }
                            // 根据standardbasis的值更新countMap
                            if (standardBasis != null) {
                                switch (standardBasis) {
                                    case "0":
                                        countMap.put("红色", countMap.get("红色") + 1);
                                        break;
                                    case "1":
                                        countMap.put("橙色", countMap.get("橙色") + 1);
                                        break;
                                    case "2":
                                        countMap.put("黄色", countMap.get("黄色") + 1);
                                        break;
                                    case "3":
                                        countMap.put("蓝色", countMap.get("蓝色") + 1);
                                        break;
                                }
                            }
                        }
                    }
                }else if (monitorName.equals("12小时降水")){
                    // 初始化四个颜色对应的计数器
                    countMap.put("红色", 0); // 0 - 红色
                    countMap.put("橙色", 0); // 1 - 橙色
                    countMap.put("黄色", 0); // 2 - 黄色
                    countMap.put("蓝色", 0); // 3 - 蓝色
                    countMap.put("站点数", countMap1.get(5));
                    // 遍历 res1，统计对应monitorname的标准值数量
                    for (Map<String, Object> map : res1) {
                        if (monitorName.equals(map.get("monitorname"))) {
                            String standardBasis = map.get("standardbasis").toString();
                            // double monitorvalue = Double.parseDouble(map.get("monitorvalue").toString());
                            // if (monitorvalue > 0 ){
                            //     countMap.put("站点数", countMap.get("站点数") + 1);
                            // }
                            // 根据standardbasis的值更新countMap
                            if (standardBasis != null) {
                                switch (standardBasis) {
                                    case "0":
                                        countMap.put("红色", countMap.get("红色") + 1);
                                        break;
                                    case "1":
                                        countMap.put("橙色", countMap.get("橙色") + 1);
                                        break;
                                    case "2":
                                        countMap.put("黄色", countMap.get("黄色") + 1);
                                        break;
                                    case "3":
                                        countMap.put("蓝色", countMap.get("蓝色") + 1);
                                        break;
                                }
                            }
                        }
                    }
                }else if (monitorName.equals("24小时降水")){
                    // 初始化四个颜色对应的计数器
                    countMap.put("红色", 0); // 0 - 红色
                    countMap.put("橙色", 0); // 1 - 橙色
                    countMap.put("黄色", 0); // 2 - 黄色
                    countMap.put("蓝色", 0); // 3 - 蓝色
                    countMap.put("站点数", countMap1.get(6));
                    // 遍历 res1，统计对应monitorname的标准值数量
                    for (Map<String, Object> map : res1) {
                        if (monitorName.equals(map.get("monitorname"))) {
                            String standardBasis = map.get("standardbasis").toString();
                            // double monitorvalue = Double.parseDouble(map.get("monitorvalue").toString());
                            // if (monitorvalue > 0 ){
                            //     countMap.put("站点数", countMap.get("站点数") + 1);
                            // }
                            // 根据standardbasis的值更新countMap
                            if (standardBasis != null) {
                                switch (standardBasis) {
                                    case "0":
                                        countMap.put("红色", countMap.get("红色") + 1);
                                        break;
                                    case "1":
                                        countMap.put("橙色", countMap.get("橙色") + 1);
                                        break;
                                    case "2":
                                        countMap.put("黄色", countMap.get("黄色") + 1);
                                        break;
                                    case "3":
                                        countMap.put("蓝色", countMap.get("蓝色") + 1);
                                        break;
                                }
                            }
                        }
                    }

                }else {
                    // 初始化四个颜色对应的计数器
                    countMap.put("红色", 0); // 0 - 红色
                    countMap.put("橙色", 0); // 1 - 橙色
                    countMap.put("黄色", 0); // 2 - 黄色
                    countMap.put("蓝色", 0); // 3 - 蓝色
                    countMap.put("站点数",0);
                    // 遍历 res1，统计对应monitorname的标准值数量
                    for (Map<String, Object> map : res1) {
                        if (monitorName.equals(map.get("monitorname"))) {
                            String standardBasis = map.get("standardbasis").toString();
                            double monitorvalue = Double.parseDouble(map.get("monitorvalue").toString());
                            if (monitorvalue > 0 ){
                                countMap.put("站点数", countMap.get("站点数") + 1);
                            }
                            // 根据standardbasis的值更新countMap
                            if (standardBasis != null) {
                                switch (standardBasis) {
                                    case "0":
                                        countMap.put("红色", countMap.get("红色") + 1);
                                        break;
                                    case "1":
                                        countMap.put("橙色", countMap.get("橙色") + 1);
                                        break;
                                    case "2":
                                        countMap.put("黄色", countMap.get("黄色") + 1);
                                        break;
                                    case "3":
                                        countMap.put("蓝色", countMap.get("蓝色") + 1);
                                        break;
                                }
                            }
                        }
                    }
                }


                // 创建一个存储当前监测类型统计数据的Map
                Map<String, Object> resultMap = new HashMap<>();
                resultMap.put("type", monitorName);
                resultMap.put("橙色", countMap.get("橙色"));
                resultMap.put("蓝色", countMap.get("蓝色"));
                resultMap.put("黄色", countMap.get("黄色"));
                resultMap.put("红色", countMap.get("红色"));
                resultMap.put("站点数", countMap.get("站点数"));

                // 将当前监测类型的统计结果添加到result1中
                result1.add(resultMap);
            }

            // 返回最终结果
            return Results.success("获取监测预警红橙黄蓝个数", 1, result1);
        } catch (Exception e) {
            return Results.fail(e.getMessage());
        }

    }

    /*获取监测预警红橙黄蓝数据*/
    @GetMapping("/getColorForInfo")
    @ResponseBody
    public Results1 getColorForInfo(HttpServletRequest request, Model model) {
        String county = request.getParameter("advname");
        String type2 = request.getParameter("type");
        String color2 = request.getParameter("color");
        int color1 = 0;
        switch (color2){
            case "红色":
                color1 = 0;
                break;
            case "橙色":
                color1 = 1;
                break;
            case "黄色":
                color1 = 2;
                break;
            case "蓝色":
                color1 = 3;
                break;
            case "站点数":
                color1 = 4;
                break;
            default:
                return null;
        }
        String county1 = "";
        String county2 = "";
        switch (county) {
            case "伊犁州直":
                county1 = "'伊宁市','察布查尔锡伯自治县','奎屯市','霍尔果斯市','伊宁县','巩留县','霍城县','新源县','昭苏县','特克斯县','尼勒克县'";
                break;
            case "伊犁河谷":
                county1 = "'伊宁市','察布查尔锡伯自治县','霍尔果斯市','伊宁县','巩留县','霍城县','新源县','昭苏县','特克斯县','尼勒克县'";
                break;
            case "察县":
                county1 = "'察布查尔锡伯自治县'";
                break;
            case "伊宁市":
                county1 = "'伊宁市'";
                break;
            case "奎屯市":
                county1 = "'奎屯市'";
                break;
            case "霍尔果斯市":
                county1 = "'霍尔果斯市'";
                break;
            case "伊宁县":
                county1 = "'伊宁县'";
                break;
            case "巩留县":
                county1 = "'巩留县'";
                break;
            case "霍城县":
                county1 = "'霍城县'";
                break;
            case "新源县":
                county1 = "'新源县'";
                break;
            case "昭苏县":
                county1 = "'昭苏县'";
                break;
            case "特克斯县":
                county1 = "'特克斯县'";
                break;
            case "尼勒克县":
                county1 = "'尼勒克县'";
                break;
            default:
                return null;
        }
        switch (county){
            case "伊犁州直":
                county2="654000";
                break;
            case "伊犁河谷":
                county2="654000";
                break;
            case "伊宁市":
                county2="654002";
                break;
            case "奎屯市":
                county2="654003";
                break;
            case "霍尔果斯市":
                county2="654004";
                break;
            case "察县":
                county2="654022";
                break;
            case "霍城县":
                county2="654023";
                break;
            case "巩留县":
                county2="654024";
                break;
            case "新源县":
                county2="654025";
                break;
            case "昭苏县":
                county2="654026";
                break;
            case "特克斯县":
                county2="654027";
                break;
            case "尼勒克县":
                county2="654028";
                break;
            default:
                return null;
        }
        try {
            StringBuilder sql = new StringBuilder();
            sql.append("select stationid,longitude,latitude,stationname,county ")
                    .append("from smallscale_station ")
                    .append("where county IN (" + county1 + ")")
            ;
            List<Map<String, Object>> res = comDisplayService.getStationInfo55(sql.toString());
            // 使用 StringJoiner 来连接结果
            StringJoiner joiner = new StringJoiner(",");
            StringJoiner joiner1 = new StringJoiner("、");
            // 遍历 res 列表，提取每个 stationid，并在添加到 joiner 时加上单引号
            for (Map<String, Object> station : res) {
                String stationId1 = (String) station.get("stationid");
                joiner.add("'" + stationId1 + "'");  // 在每个 stationid 前后加上单引号
            }
            // 最终结果就是你想要的字符串
            String result = joiner.toString();
            StringBuilder sql1 = new StringBuilder();
            if(color1 == 4){
                sql1.append("select stationid,warningtype,time AS warningtime,monitorvalue,standardbasis ")
                        .append("FROM warn_moni_info ")
                        //.append("where stationid IN (" + result + ") ")
                        .append("WHERE county = '"+county2+"' ")
                        .append("and monitorname = '" + type2 + "' ")
                        .append("and monitorvalue > 0 ")
                        .append("and isremoved != '1'");
            }else{
                sql1.append("select stationid,warningtype,time AS warningtime,monitorvalue,standardbasis ")
                        .append("FROM warn_moni_info ")
                        //.append("where stationid IN (" + result + ") ")
                        .append("WHERE county = '"+county2+"' ")
                        .append("and monitorname = '" + type2 + "' ")
                        .append("and standardbasis = '" + color1 + "' ")
                        .append("and isremoved != '1'");
            }

            List<Map<String, Object>> res1 = comDisplayService.getWarnInfoAndOther(sql1.toString());
            List<Map<String, Object>> res2 = new ArrayList<>();
            for (Map<String, Object> warnInfo : res1) {
                for (Map<String, Object> stationInfo : res) {
                    if (warnInfo.get("stationid").equals(stationInfo.get("stationid"))) {
                        warnInfo.put("latitude", stationInfo.get("latitude"));
                        warnInfo.put("longitude", stationInfo.get("longitude"));
                        warnInfo.put("stationname", stationInfo.get("stationname"));
                        warnInfo.put("county", stationInfo.get("county"));
                        break;
                    }
                }

            }
            String warningtype ="";
            String warningtime ="";
            for (Map<String, Object> map : res1) {
                String color = (String) map.get("standardbasis");
                  String stationname =(String) map.get("stationname");
                   warningtype =(String) map.get("warningtype");
                   warningtime =(String) map.get("warningtime");
                   String type3 ="";
                  switch (color){
                    case "0":
                        type3 = "红色预警";
                        break;
                    case "1":
                        type3 = "橙色预警";
                        break;
                    case "2":
                        type3 = "黄色预警";
                        break;
                    case "3":
                        type3 = "蓝色预警";
                        break;
                    default:
                        type3 = "无";
                }

                  joiner1.add(stationname);
                  // String yujing = "短时天气提醒: "+stationname+""+warningtype+",请加强防范。( "+county+"气象台"+warningtime+"发布)";
                map.put("type",type3);
                //map.put("yujing",yujing);
            }
            String name = joiner1.toString();
            String yujing ="";
            if (type2 != null && type2.contains("60分钟降水")){
                 yujing = "短时强降水天气提醒: 近1小时，"+name+""+warningtype+",请加强防范。( "+county+"气象台"+warningtime+"发布)";
            // } else if (type2 != null && type2.contains("降水")){
            //      yujing = "天气提醒: 近"+type2+"，"+name+""+warningtype+",请加强防范。( "+county+"气象台"+warningtime+"发布)";
             } else {
                 yujing = "天气提醒: "+name+""+warningtype+",请加强防范。( "+county+"气象台"+warningtime+"发布)";
            }
            Map<String, Object> map = new HashMap<>();
            map.put("yujing", yujing);  // 假设 yujing 是已定义的变量
            res2.add(map);
            return Results1.success("获取红黄蓝绿具体数据", 1, res1,res2);
        } catch (Exception e) {
            return Results1.fail(e.getMessage());
        }
    }

/**
 * 获取预警信号、风、降水、能见度数据
 */
@GetMapping("/getWarnInfoAndOther")
@ResponseBody
public Results1 getWarnInfoAndOther(HttpServletRequest request, Model model){
    String county = request.getParameter("advname");
    String type = request.getParameter("type");
    String county1 = "";
    switch (county){
        case "伊犁州直":
            county1 = "'伊宁市','察布查尔锡伯自治县','奎屯市','霍尔果斯市','伊宁县','巩留县','霍城县','新源县','昭苏县','特克斯县','尼勒克县'";
            break;
        case "伊犁河谷":
            county1 = "'伊宁市','察布查尔锡伯自治县','霍尔果斯市','伊宁县','巩留县','霍城县','新源县','昭苏县','特克斯县','尼勒克县'";
            break;
        case "察县":
            county1 = "'察布查尔锡伯自治县'";
            break;
        case "伊宁市":
            county1 = "'伊宁市'";
            break;
        case "奎屯市":
            county1 = "'奎屯市'";
            break;
        case "霍尔果斯市":
            county1 = "'霍尔果斯市'";
            break;
        case "伊宁县":
            county1 = "'伊宁县'";
            break;
        case "巩留县":
            county1 = "'巩留县'";
            break;
        case "霍城县":
            county1 = "'霍城县'";
            break;
        case "新源县":
            county1 = "'新源县'";
            break;
        case "昭苏县":
            county1 = "'昭苏县'";
            break;
        case "特克斯县":
            county1 = "'特克斯县'";
            break;
        case "尼勒克县":
            county1 = "'尼勒克县'";
            break;
        default:
            return null;
    }
    try {
        StringBuilder sql = new StringBuilder();
        sql.append("select stationid,longitude,latitude,stationname ")
                .append("from smallscale_station ")
                .append("where county IN (" + county1 + ")");
        List<Map<String, Object>> res = comDisplayService.getStationInfo(sql.toString());
        // 使用 StringJoiner 来连接结果
        StringJoiner joiner = new StringJoiner(",");

        // 遍历 res 列表，提取每个 stationid，并在添加到 joiner 时加上单引号
        for (Map<String, Object> station : res) {
            String stationId1 = (String) station.get("stationid");
            joiner.add("'" + stationId1 + "'");  // 在每个 stationid 前后加上单引号
        }

        // 最终结果就是你想要的字符串
        String result = joiner.toString();
        StringBuilder sql1 = new StringBuilder();

        if (type.equals("预警信号")){
            sql1.append("select area,color,CONCAT ( TYPE, '', color ) AS TYPE,\n" +
                    "\tCONCAT ( area, '发布', TYPE, '', color, '预警' ) AS description,")
                    .append("announcedtime,description AS biaotou,defenseguide,")
                    .append("standard AS warningtype ")
                    .append("FROM warn_signal_info ")
                    .append("where area IN ("+ county1 +")" );
            List<Map<String, Object>> res1 =   comDisplayService.getWarnInfoAndOther1(sql1.toString());
            for (Map<String, Object> warnInfo : res1) {
                    if (warnInfo.get("area").equals("伊宁市")){
                        warnInfo.put("latitude", 43.9406);
                        warnInfo.put("longitude", 81.3264);
                        warnInfo.put("stationname", "伊宁");
                    }else if (warnInfo.get("area").equals("奎屯市")){
                        warnInfo.put("latitude", 43.8367);
                        warnInfo.put("longitude", 84.4694);
                        warnInfo.put("stationname", "独库下行K646 100应用气象观测站（交通）");

                    }else if (warnInfo.get("area").equals("霍尔果斯市")){
                        warnInfo.put("latitude", 44.1725);
                        warnInfo.put("longitude", 80.4083);
                        warnInfo.put("stationname", "霍尔果斯");

                    }else if (warnInfo.get("area").equals("察布查尔锡伯县")){
                        warnInfo.put("latitude", 43.8317);
                        warnInfo.put("longitude", 81.1481);
                        warnInfo.put("stationname", "察布查尔国家气象观测站");

                    }else if (warnInfo.get("area").equals("伊宁县")){
                        warnInfo.put("latitude", 43.9725);
                        warnInfo.put("longitude", 81.5286);
                        warnInfo.put("stationname", "伊宁县");

                    }else if (warnInfo.get("area").equals("巩留县")){
                        warnInfo.put("latitude", 43.4717);
                        warnInfo.put("longitude", 82.2247);
                        warnInfo.put("stationname", "巩留");

                    }else if (warnInfo.get("area").equals("霍城县")){
                        warnInfo.put("latitude", 43.6827);
                        warnInfo.put("longitude", 82.6417);
                        warnInfo.put("stationname", "霍城");

                    }else if (warnInfo.get("area").equals("新源县")){
                        warnInfo.put("latitude", 43.4458);
                        warnInfo.put("longitude", 83.2569);
                        warnInfo.put("stationname", "新源");

                    }else if (warnInfo.get("area").equals("昭苏县")){
                        warnInfo.put("latitude", 42.8119);
                        warnInfo.put("longitude", 80.8106);
                        warnInfo.put("stationname", "昭苏县喀拉苏镇");

                    }else if (warnInfo.get("area").equals("特克斯县")){
                        warnInfo.put("latitude", 43.2217);
                        warnInfo.put("longitude", 81.8383);
                        warnInfo.put("stationname", "特克斯县");

                    }else if (warnInfo.get("area").equals("尼勒克县")){
                        warnInfo.put("latitude", 43.7089);
                        warnInfo.put("longitude", 83.2944);
                        warnInfo.put("stationname", "尼勒克县种蜂场");

                    }
            }
            Map<String, Integer> colorCount = new HashMap<>();
            colorCount.put("红色", 0);
            colorCount.put("橙色", 0);
            colorCount.put("黄色", 0);
            colorCount.put("蓝色", 0);

// 遍历每个预警信息
            for (Map<String, Object> warnInfo : res1) {
                // 获取颜色字段
                String color = (String) warnInfo.get("color");

                // 更新对应颜色的计数
                if (color != null && colorCount.containsKey(color)) {
                    colorCount.put(color, colorCount.get(color) + 1);
                }
            }
            return Results1.success("获取预警信号数据", 1, res1, colorCount);
        }else if (type.equals("灾害性天气")){
         sql1.append("select stationid,disweather_name,happen_time,disweather_result ")
                 .append("FROM disweather_moni_info ")
                 .append("where stationid IN (" + result + ") ");
         List<Map<String, Object>> res1 = comDisplayService.getWarnInfoAndOther2(sql1.toString());
            Map<String, Integer> colorCount1= new HashMap<>();
            colorCount1.put("红色", 0);
            colorCount1.put("橙色", 0);
            colorCount1.put("黄色", 0);
            colorCount1.put("蓝色", 0);
         for (Map<String, Object> warnInfo : res1) {
             for (Map<String, Object> stationInfo : res) {
                 if (warnInfo.get("stationid").equals(stationInfo.get("stationid"))){
                     warnInfo.put("latitude", stationInfo.get("latitude"));
                     warnInfo.put("longitude", stationInfo.get("longitude"));
                     warnInfo.put("stationname", stationInfo.get("stationname"));
                     break;
                 }
             }

         }
            return Results1.success("获取预警信号数据", 1, res1, colorCount1);
        }else {
        sql1.append("select stationid,warningtype,warningtime,monitorvalue,standardbasis ")
                .append("FROM warn_moni_info ")
                .append("where stationid IN (" + result + ") ")
                .append("AND isremoved != '1' ")
                .append("AND warningtype LIKE '%")
                .append(type)
                .append("%'");
            List<Map<String, Object>> res1 = comDisplayService.getWarnInfoAndOther(sql1.toString());
            for (Map<String, Object> warnInfo : res1) {
                for (Map<String, Object> stationInfo : res) {
                    if (warnInfo.get("stationid").equals(stationInfo.get("stationid"))){
                        warnInfo.put("latitude", stationInfo.get("latitude"));
                        warnInfo.put("longitude", stationInfo.get("longitude"));
                        warnInfo.put("stationname", stationInfo.get("stationname"));
                        break;
                    }
                }
            }
            for (Map<String, Object> map : res1) {
                String color = (String) map.get("standardbasis");
                switch (color){
                    case "0":
                        type = "红色预警";
                        break;
                    case "1":
                        type = "橙色预警";
                        break;
                    case "2":
                        type = "黄色预警";
                        break;
                    case "3":
                        type = "蓝色预警";
                        break;
                        default:
                            type = "无";
                }
                map.put("type",type);
            }


            Map<String, Integer> colorCount = new HashMap<>();
            colorCount.put("红色", 0);
            colorCount.put("橙色", 0);
            colorCount.put("黄色", 0);
            colorCount.put("蓝色", 0);

// 遍历每个预警信息
            for (Map<String, Object> warnInfo : res1) {
                // 获取颜色字段
                String color = (String) warnInfo.get("standardbasis");
                switch (color){
                    case "0":
                        color = "红色";
                        break;
                    case "1":
                        color = "橙色";
                        break;
                    case "2":
                        color = "黄色";
                        break;
                    case "3":
                        color = "蓝色";
                        break;
                        default:
                        color = "无";
                }
                // 更新对应颜色的计数
                if (color != null && colorCount.containsKey(color)) {
                    colorCount.put(color, colorCount.get(color) + 1);
                }
            }
            return Results1.success("获取预警信号数据", 1, res1, colorCount);
        }
    } catch (Exception e) {
        return Results1.fail(e.getMessage());
    }
}
/**
 * 获取伊宁市过去24小时雨温风
 */
@GetMapping("/get24HourInfoY")
@ResponseBody
public Results get24HourInfoY(HttpServletRequest request, Model model) {
    String  stationId = "51431";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    // 获取当前时间
    Date date = new Date();

    // 获取 Calendar 实例并设置当前时间
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    // 将时间减去24小时
    calendar.add(Calendar.HOUR_OF_DAY, -24);

    // 将分钟、秒钟和毫秒设置为0
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    // 格式化并输出结果
    String startTime = simpleDateFormat.format(calendar.getTime());
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    // 处理 endTime
    calendar.setTime(date);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    // 获取调整后的 endTime
    String endTime = simpleDateFormat.format(calendar.getTime());
    ArrayList<Object> timeList = new ArrayList<>();
    for (int i = 1; i < 25; i++) {
        int futureHour = (hour + i) % 24;  // 计算从当前小时开始的过去24小时
        timeList.add(futureHour);
    }

    try {
        StringBuilder sql = new StringBuilder();
        // 拼接每个查询
        sql.append("SELECT maxtemp,rain,instantwindv,instantwindd ")
                .append("FROM msgmediumsmallscale ")
                .append("WHERE observtime BETWEEN ")
                .append("'").append(startTime).append("' AND ")
                .append("'").append(endTime).append("' AND ")
                .append("stationid = '").append(stationId).append("' ")
                .append("ORDER BY observtime ASC");
        List<Map<String, Object>> hourInfoNew = comDisplayService.get12HourInfoNew(sql.toString());
        Map<String, List<Object>> result = new HashMap<>();
        List<Object> rainList = new ArrayList<>();
        List<Object> maxtempList = new ArrayList<>();
        List<Object> instantwindvList = new ArrayList<>();
        List<Object> instantwinddList = new ArrayList<>();
        List<Object> windLvList =new ArrayList<>();
        for (int i = 0; i < 24; i++) {
            if (i < hourInfoNew.size()) {
                rainList.add(hourInfoNew.get(i).get("rain"));
                maxtempList.add(hourInfoNew.get(i).get("maxtemp"));
                instantwindvList.add(hourInfoNew.get(i).get("instantwindv"));
                instantwinddList.add(hourInfoNew.get(i).get("windd"));
                windLvList.add(WebCtrlData.FengSuToFengJi(Double.parseDouble(hourInfoNew.get(i).get("instantwindv").toString())));
            } else {
                rainList.add(0.0);
                maxtempList.add(0.0);
                instantwindvList.add(0.0);
                instantwinddList.add(0.0);
                windLvList.add(0);
            }
        }
        result.put("rain", rainList);
        result.put("maxtemp", maxtempList);
        result.put("instantwindv", instantwindvList);
        result.put("instantwindd", instantwinddList);
        result.put("time", timeList);
        result.put("windLv", windLvList);


        return Results.success("获取过去24小时数据", 1, result);
    }catch (Exception e){
        return Results.fail(e.getMessage());
    }
}

    /**
     * 获取产品文档
     */


    /**
     * 获取伊宁市未来5天雨温风
     */
    @GetMapping("/get5DayInfoF")
    @ResponseBody
    public Results get24HourInfoF(HttpServletRequest request, Model model) {
        String  stationId = "51431";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        // 获取当前时间
        Date date = new Date();
        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 处理 endTime
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, 24); // 将时间加上24小时
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 获取调整后的 endTime
        String endTime = simpleDateFormat.format(calendar.getTime());
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        // 获取未来12小时后的日期
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, 120); // 将时间加上120小时 5天
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        String futureTime = simpleDateFormat.format(calendar.getTime());
        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
        String dateStart = null;
        String dateEnd = null;

        try {
            // 将 endTime 和 futureTime 转换为 Date 对象
            Date futureTimeDate = simpleDateFormat.parse(futureTime);
            Date futureTimeDate1 = simpleDateFormat.parse(endTime);

            // 格式化为 yyyy-MM-dd 形式
            dateStart = sim.format(futureTimeDate1);
            dateEnd = sim.format(futureTimeDate);

        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            StringBuilder sql1 = new StringBuilder();
            sql1.append("SELECT maxtemp,wind,rain,windd,TO_CHAR(datechar, 'DD') || '日' || ntimes ||'时' AS times ")
                    .append("FROM ybzz_forecastfinal ")
                    .append("WHERE datechar BETWEEN ")
                    .append("'").append(dateStart).append("' AND ")
                    .append("'").append(dateEnd).append("' AND ")
                    .append("forecasttype = '12' AND ")
                    .append("stationid = '").append(stationId).append("' ")
                    .append("ORDER BY datechar ASC");
            List<Map<String, Object>> hourInfo = comDisplayService.get24HourInfoFur1(sql1.toString());
            Map<String, List<Object>> result = new HashMap<>();
            List<Object> rainList = new ArrayList<>();
            List<Object> maxtempList = new ArrayList<>();
            List<Object> instantwindvList = new ArrayList<>();
            List<Object> instantwinddList = new ArrayList<>();
            List<Object> windLvList = new ArrayList<>();
            List<Object> timeList = new ArrayList<>();
            for (int i = 0; i < hourInfo.size(); i++) {
                if (i < hourInfo.size()) {
                    rainList.add( hourInfo.get(i).get("rain"));
                    maxtempList.add(hourInfo.get(i).get("maxtemp"));
                    instantwindvList.add( hourInfo.get(i).get("wind"));
                    instantwinddList.add(hourInfo.get(i).get("windd"));
                    timeList.add(hourInfo.get(i).get("times"));
                    windLvList.add(WebCtrlData.FengSuToFengJi(Double.parseDouble(hourInfo.get(i).get("wind").toString())));
                } else {
                    rainList.add(0.0);
                    maxtempList.add(0.0);
                    instantwindvList.add(0.0);
                    instantwinddList.add(0.0);
                    timeList.add("xx日xx时");
                    windLvList.add(0);
                }
            }
            result.put("rain", rainList);
            result.put("maxtemp", maxtempList);
            result.put("instantwindv", instantwindvList);
            result.put("instantwindd", instantwinddList);
            result.put("time", timeList);
            result.put("windLv", windLvList);


            return Results.success("获取未来5天数据", 1, result);
        }  catch (Exception e){
            return Results.fail(e.getMessage());
        }
    }

       /*
 //     * 获取景区基本信息
 //     * */
    @GetMapping("/getTourInfo")
    @ResponseBody
    public Results getTourInfo(HttpServletRequest request, Model model) {
        // StringBuilder sql = new StringBuilder();
        // sql.append("SELECT stationid,stationname,longitude,latitude,text,areaname ")
        //         .append("FROM tour_stations ");
        // List<Map<String, Object>> res = null;
        // try {
        //     res = comDisplayService.getTourInfo(sql.toString());
        // } catch (Exception e) {
        //     return Results.fail(e.getMessage());
        // }
        // return Results.success("获取景区基本信息", 1, res);
        String stationid = request.getParameter("stationid");
        List<TourStation> resultList = new ArrayList<TourStation>();
        List<tour_stations> dataList = tourService.getAllTourStations(stationid);
        //List<tour_actual_img> actual_imgs = tourService.getNewestActualImg();
        String urlpath ;
        if (operatingSystem.equals("Windows")){
            urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\actualImg\\";
        }else {
            urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/actualImg/";
        }
        FileUtil.mkDirs(urlpath);// 创建文件夹
        // 当文件达到100张时清除
        FileUtil.ClearTempFiles(urlpath, 100);
        // 处理得到最新图片
        for (tour_stations station : dataList) {
                    // 获取最新的图片
                    String fileName = station.getStationname() + ".jpg";
                    if (!new File(urlpath + fileName).exists()) {
                        Map<String, Object> map = new HashMap<String, Object>();
                        map.put("stationid", station.getStationid());
                        map.put("collectionName", "image_file");
                        map.put("advCode", DbConfig.advCode);
                        byte[] data = ms.selectData(map);
                        if (data == null) {
                            return null;
                        }
                        String localPath = urlpath + fileName;
                        FileUtil.bytesToFile(data, localPath);
                    }
                    // 赋值
                    TourStation tourStation = new TourStation();
                    tourStation.setStationId(station.getStationid());
                    tourStation.setStationName(station.getStationname());
                    tourStation.setAlti(station.getAltitude());
                    tourStation.setLon(station.getLongitude());
                    tourStation.setLat(station.getLatitude());
                    if (station.getLongitude() != null && station.getLatitude() != null) {
                        DmMapPoint dmDot = new DmMapPoint(station.getLongitude(), station.getLatitude());
                        DmMapPoint ltDot = transformService.LonLatConvertToLambert(dmDot.x, dmDot.y);
                        tourStation.setY(ltDot.y);
                        tourStation.setX(ltDot.x);
                    }
                    tourStation.setGrade(station.getGrade());
                    tourStation.setAreaName(station.getAreaname());
                    if (operatingSystem.equals("Windows")){
                        tourStation.setImagePath("Temp\\actualImg\\" + fileName);
                    }else {
                        tourStation.setImagePath("Temp/actualImg/" + fileName);
                    }

                    tourStation.setText(station.getText());
                    tourStation.setPeople(station.getPeople());
                    tourStation.setPhone(station.getPhone());
                    tourStation.setLocation(station.getLocation());
                    tourStation.setSuggest(station.getSuggest());
                    resultList.add(tourStation);
        }
        return Results.success("获取景区基本信息", 1, resultList);
    }
/*
 //     * 获取景区天气预报信息
 //     * */
    @GetMapping("/getTourForecast")
    @ResponseBody
    public Results getTourForecast(HttpServletRequest request, Model model) {
        //SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // // 获取当前时间
        // Date date = new Date();
        // // 获取 Calendar 实例并设置当前时间
        // Calendar calendar = Calendar.getInstance();
        // // 获取未来12小时后的日期
        // calendar.setTime(date);
        // calendar.add(Calendar.HOUR_OF_DAY, 24); // 将时间加上24小时
        // calendar.set(Calendar.MINUTE, 0);
        // calendar.set(Calendar.SECOND, 0);
        // calendar.set(Calendar.MILLISECOND, 0);
        //
        // String futureTime = simpleDateFormat.format(calendar.getTime());
        String observtime = request.getParameter("datechar");
        String ntimes = request.getParameter("ntimes");
        String timechar = request.getParameter("timechar");
        List<Map<String, Object>> res = null;
        List<Map<String, Object>> res1 = null;
        StringBuilder sql = new StringBuilder();
        StringBuilder sql1 = new StringBuilder();
        sql.append("SELECT datechar,timechar,ntimes ")
                .append("FROM tour_fcst ")
                .append("ORDER BY datechar desc ")
                .append("LIMIT 1");
        try {
            res = comDisplayService.getNewTime(sql.toString());
            String datechar1 = res.get(0).get("datechar").toString();
            String timechar1 = res.get(0).get("timechar").toString();
            String ntimes1 = res.get(0).get("ntimes").toString();
            if (observtime.isEmpty()){
                sql1.append("SELECT stationname,maxtemp,winds,weather1 ")
                        .append("FROM tour_fcst ")
                        .append("WHERE datechar = '"+datechar1+"' ")
                        .append("AND timechar = '"+timechar1+"' ")
                        .append("AND ntimes = '"+ntimes1+"' ");
            }else {
                sql1.append("SELECT stationname,maxtemp,winds,weather1 ")
                        .append("FROM tour_fcst ")
                        .append("WHERE datechar = '"+observtime+"' ")
                        .append("AND timechar = '"+timechar+"' ")
                        .append("AND ntimes = '"+ntimes+"' ");
            }
            res1 = comDisplayService.getTourForecast(sql1.toString());
        } catch (Exception e) {
            return Results.fail(e.getMessage());
        }
           return Results.success("获取景区天气预报信息", 1, res1);
    }

    /*
 //     * 获取卫星遥感监测信息
 //     * */
    @RequestMapping("/getMonitoringInfo")
    @ResponseBody
    public Results getMonitoringInfo(HttpServletRequest request, Model model) {
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT datechar,yttype ")
                .append("FROM satellitenephoram3 ")
                .append("WHERE datechar BETWEEN '"  +startTime +"' AND '" +endTime+"' ");
        List<Map<String, Object>> res = null;
        try {
             res = comDisplayService.getMonitoringInfo(sql.toString());
        } catch (Exception e) {
            return Results.fail(e.getMessage());
        }
          return Results.success("获取卫星遥感监测信息", 1, res);
    }


    /*
    //     * 获取相近站点未来过去12小时雨温风数据
    //     * */
        @GetMapping("/getNearHourInfo")
        @ResponseBody
        public Results  getNewHourInfo(HttpServletRequest request, Model model) {
            String longitude = request.getParameter("longitude");
            String latitude = request.getParameter("latitude");
          String  county1 = "'伊宁市','察布查尔锡伯自治县','奎屯市','霍尔果斯市','伊宁县','巩留县','霍城县','新源县','昭苏县','特克斯县','尼勒克县'";

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            // 获取当前时间
            Date date = new Date();

            // 获取 Calendar 实例并设置当前时间
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);

            // 获取当前时间的分钟数
            int minute = calendar.get(Calendar.MINUTE);

            // 计算 startTime：前一个小时的最后一个 20 分钟结束时间
            calendar.add(Calendar.HOUR_OF_DAY, -1);  // 将时间减去 1 小时
            int startMinute = (minute / 20) * 20;  // 向下取整到 20 的倍数
            calendar.set(Calendar.MINUTE, 10);  // 前一个小时的最后一个 20 分钟结束时间
            calendar.set(Calendar.SECOND, 0);  // 秒数设置为 0
            calendar.set(Calendar.MILLISECOND, 0);  // 毫秒数设置为 0
            String startTime = simpleDateFormat.format(calendar.getTime());  // 格式化 startTime

            // 计算 endTime：当前小时内最后一个 20 分钟结束时间
            calendar.setTime(date);  // 重置到当前时间
            int endMinute = (minute / 20) * 20;  // 向下取整到 20 的倍数
            calendar.set(Calendar.MINUTE, endMinute + 9);  // 设置为当前小时最后一个 20 分钟区间的结束时间
            calendar.set(Calendar.SECOND, 59);  // 秒数设置为 59，确保是结束时刻
            calendar.set(Calendar.MILLISECOND, 999);  // 毫秒数设置为 999，确保精确
            String endTime = simpleDateFormat.format(calendar.getTime());  // 格式化 endTime
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            // 获取未来12小时后的日期
            calendar.setTime(date);
            calendar.add(Calendar.HOUR_OF_DAY, 12); // 将时间加上12小时
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);

            String futureTime = simpleDateFormat.format(calendar.getTime());
            SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
            String dateStart = null;
            String dateEnd = null;

            try {
                // 将 endTime 和 futureTime 转换为 Date 对象
                Date futureTimeDate = simpleDateFormat.parse(futureTime);
                Date futureTimeDate1 = simpleDateFormat.parse(endTime);

                // 格式化为 yyyy-MM-dd 形式
                dateStart = sim.format(futureTimeDate1);
                dateEnd = sim.format(futureTimeDate);
            } catch (Exception e) {
                e.printStackTrace();
            }
            Object stationId = null;
            try {
                StringBuilder sql2 = new StringBuilder();
                sql2.append("select stationid,longitude,latitude,stationname ")
                        .append("from smallscale_station ")
                        .append("where county IN (" + county1 + ")");
                List<Map<String, Object>> res = comDisplayService.getStationInfo(sql2.toString());
                Map<String, Object> stationInfo= findNearestStation(res, Double.parseDouble(latitude), Double.parseDouble(longitude));
                 stationId = stationInfo.get("stationid");
                StringBuilder sql = new StringBuilder();
                // 拼接每个查询
                sql.append("SELECT  TO_CHAR(datetime, 'HH') AS hour, ")
                        .append("FLOOR(EXTRACT(MINUTE FROM datetime) / 10) * 10 AS minute_interval, ")
                        .append("TO_CHAR(datetime, 'HH') || '时' || LPAD((FLOOR(EXTRACT(MINUTE FROM datetime) / 10) * 10)::text, 2, '0') || '分' AS times, ")
                        .append("SUM(pre) AS total_pre ")
                        .append("FROM msg_rain_minute ")
                        .append("WHERE datetime BETWEEN ")
                        .append("'").append(startTime).append("' AND ")
                        .append("'").append(endTime).append("' AND ")
                        .append("station_id_c = '").append(stationId).append("' ")
                        .append("GROUP by hour,minute_interval ")
                        .append("ORDER BY hour,minute_interval;");
                List<Map<String, Object>> rainInfo = comDisplayService.get24Hou(sql.toString());
                StringBuilder sql4 = new StringBuilder();
                sql4.append("SELECT  TO_CHAR(datetime, 'HH') AS hour, ")
                        .append("FLOOR(EXTRACT(MINUTE FROM datetime) / 10) * 10 AS minute_interval, ")
                        .append("TO_CHAR(datetime, 'HH') || '时' || LPAD((FLOOR(EXTRACT(MINUTE FROM datetime) / 10) * 10)::text, 2, '0') || '分' AS times, ")
                        .append("MAX(tem) AS total_pre ")
                        .append("FROM msg_other_minute ")
                        .append("WHERE datetime BETWEEN ")
                        .append("'").append(startTime).append("' AND ")
                        .append("'").append(endTime).append("' AND ")
                        .append("station_id_c = '").append(stationId).append("' ")
                        .append("GROUP by hour,minute_interval ")
                        .append("ORDER BY hour,minute_interval;");
                List<Map<String, Object>> temInfo = comDisplayService.get24Hou(sql4.toString());
                StringBuilder sql3 = new StringBuilder();
                // 拼接每个查询
                sql3.append("WITH ranked_data AS (\n" +
                        "    SELECT\n" +
                        "        TO_CHAR(datetime, 'HH') AS hour,  \n" +
                        "        FLOOR(EXTRACT(MINUTE FROM datetime) / 10) * 10 AS minute_interval,  \n" +
                        "        TO_CHAR(datetime, 'HH') || '时' || LPAD((FLOOR(EXTRACT(MINUTE FROM datetime) / 10) * 10)::text, 2, '0') || '分' AS times,  \n" +
                        "        win_s_avg_2mi,\n" +
                        "        win_d_avg_2mi,\n" +
                        "        ROW_NUMBER() OVER (PARTITION BY TO_CHAR(datetime, 'HH'), FLOOR(EXTRACT(MINUTE FROM datetime) / 10) * 10 \n" +
                        "                           ORDER BY win_s_avg_2mi DESC) AS rn  \n" +
                        "    FROM\n" +
                        "        msg_other_minute\n" +
                        "    WHERE\n" +
                        "        datetime BETWEEN TO_TIMESTAMP('" + startTime + "', 'YYYY-MM-DD HH24:MI:SS') AND TO_TIMESTAMP('" + endTime + "', 'YYYY-MM-DD HH24:MI:SS')  \n" +
                        ")\n" +
                        "SELECT\n" +
                        "    hour,\n" +
                        "    minute_interval,\n" +
                        "    times,\n" +
                        "    win_s_avg_2mi AS total_pre,  \n" +
                        "    win_d_avg_2mi  \n" +
                        "FROM\n" +
                        "    ranked_data\n" +
                        "WHERE\n" +
                        "    rn = 1 \n" +
                        "ORDER BY\n" +
                        "    hour, minute_interval;");
                List<Map<String, Object>> windInfo = comDisplayService.getWind(sql3.toString());
                StringBuilder sql1 = new StringBuilder();
                sql1.append("SELECT maxtemp,wind,rain,windd, ")
                        .append("TO_CHAR(datechar, 'DD') || '日' || CAST(ntimes AS VARCHAR) || '时' AS times ")
                        .append("FROM ybzz_forecastfinal ")
                        .append("WHERE datechar = ")
                        .append("'").append(dateEnd).append("' AND ")
                        .append("forecasttype = '3' AND ")
                        .append("stationid = '").append(stationId).append("' ")
                        .append("ORDER BY ntimes ASC");

                List<Map<String, Object>> hourInfo = comDisplayService.get24HourInfoFu(sql1.toString());
                Map<String, List<Object>> result = new HashMap<>();
                ArrayList<Object> timesList = new ArrayList<>();
                List<Object> rainList = new ArrayList<>();
                List<Object> maxtempList = new ArrayList<>();
                List<Object> instantwindvList = new ArrayList<>();
                List<Object> instantwinddList = new ArrayList<>();
                for (int i = 0; i < 6; i++) {
                    if (i < rainInfo.size()){
                        rainList.add(rainInfo.get(i).get("total_pre"));
                        timesList.add(rainInfo.get(i).get("times"));
                    }else {
                        rainList.add(0.0);
                        timesList.add("xx时xx分");

                    }
                }

                for (int i = 0; i < 6; i++) {
                    if (i < temInfo.size()){
                        maxtempList.add(temInfo.get(i).get("total_pre"));
                    }else {
                        maxtempList.add(0.0);
                    }
                }
                for (int i = 0; i < 6; i++) {
                    if (i < windInfo.size()){
                        instantwindvList.add(windInfo.get(i).get("total_pre"));
                        instantwinddList.add(windInfo.get(i).get("wind_d_avg_1mi"));
                    }else {
                        instantwinddList.add(0.0);
                        instantwindvList.add(0.0);
                    }
                }
                for (int i = 0; i < 8; i++) {
                    if (i < hourInfo.size()) {
                        rainList.add( hourInfo.get(i).get("rain"));
                        maxtempList.add(hourInfo.get(i).get("maxtemp"));
                        instantwindvList.add( hourInfo.get(i).get("wind"));
                        instantwinddList.add(hourInfo.get(i).get("windd"));
                        timesList.add(hourInfo.get(i).get("times"));
                    } else {
                        rainList.add(0.0);
                        maxtempList.add(0.0);
                        instantwindvList.add(0.0);
                        instantwinddList.add(0.0);
                        timesList.add("XX日XX分");
                    }
                }

                result.put("rain", rainList);
                result.put("maxtemp", maxtempList);
                result.put("instantwindv", instantwindvList);
                result.put("instantwindd", instantwinddList);
                result.put("times", timesList);
                return Results.success("获取站点过去一小时未来12小时数据", 1, result);
            }  catch (Exception e){
                return Results.fail(e.getMessage());
            }
        }

    /**
     * 获取站点24小时数据
     */
    @GetMapping("/get24HourInfo")
    @ResponseBody
    public Results get24HourInfo(HttpServletRequest request, Model model) {
        String county = request.getParameter("advname");
        String stationId = "";
        switch (county) {
            case "伊犁州直":
                stationId = "51431";
                break;
            case "伊犁河谷":
                stationId = "51431";
                break;
            case "伊宁市":
                stationId = "51431";
                break;
            case "奎屯市":
                stationId = "Y5169";
                break;
            case "霍尔果斯市":
                stationId = "51328";
                break;
            case "察县":
                stationId = "51430";
                break;
            case "伊宁县":
                stationId = "51434";
                break;
            case "巩留县":
                stationId = "51435";
                break;
            case "霍城县":
                stationId = "51329";
                break;
            case "新源县":
                stationId = "51436";
                break;
            case "昭苏县":
                stationId = "51523";
                break;
            case "特克斯县":
                stationId = "51438";
                break;
            case "尼勒克县":
                stationId = "51440";
                break;
            default:
                return null;
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        // 获取当前时间
        Date date = new Date();

        // 获取 Calendar 实例并设置当前时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        // 将时间减去12小时
        calendar.add(Calendar.HOUR_OF_DAY, -12);
        // 将分钟、秒钟和毫秒设置为0
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 格式化并输出结果
        String startTime = simpleDateFormat.format(calendar.getTime());
        // 处理 endTime
        calendar.setTime(date);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 获取调整后的 endTime
        String endTime = simpleDateFormat.format(calendar.getTime());
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, 1); // 将时间加上1小时
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        // 获取调整后的 endTime
        String endTime1 = simpleDateFormat.format(calendar.getTime());
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        // 获取未来12小时后的日期
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, 36); // 将时间加上12小时
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        String futureTime = simpleDateFormat.format(calendar.getTime());
        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateStart = null;
        String dateEnd = null;

        try {
            // 将 endTime 和 futureTime 转换为 Date 对象
            Date futureTimeDate = simpleDateFormat.parse(futureTime);
            Date futureTimeDate1 = simpleDateFormat.parse(endTime1);

            // 格式化为 yyyy-MM-dd 形式
            dateStart = sim.format(futureTimeDate1);
            dateEnd = sim.format(futureTimeDate);

        } catch (Exception e) {
            e.printStackTrace();
        }


        // // 如果你想获取未来12小时的小时数，构建一个小时数列表
        // StringBuilder hours = new StringBuilder();
        // for (int i = 1; i < 13; i++) {
        //     int futureHour = (hour + i) % 24;  // 计算从当前小时开始的未来12小时
        //     if (i > 1) {
        //         hours.append(",");  // 添加分隔符
        //     }
        //     hours.append(String.format("%02d", futureHour));  // 格式化为两位数
        // }

        try {
            StringBuilder sql = new StringBuilder();
            // 拼接每个查询
            sql.append("SELECT maxtemp,rain,winddirect,instantwindv ")
                    .append("FROM msgmediumsmallscale ")
                    .append("WHERE observtime BETWEEN ")
                    .append("'").append(startTime).append("' AND ")
                    .append("'").append(endTime).append("' AND ")
                    .append("stationid = '").append(stationId).append("' ")
                    .append("ORDER BY observtime ASC");
            List<Map<String, Object>> hourInfoNew = comDisplayService.get24HourInfoNew(sql.toString());
            StringBuilder sql1 = new StringBuilder();
            sql1.append("SELECT CAST( datechar AS TIMESTAMP ) + ( ntimes || 'hour' ) :: INTERVAL AS datechar,maxtemp,wind,windd,rain ")
                    .append("FROM ybzz_forecastfinal ")
                    .append("WHERE CAST ( datechar AS TIMESTAMP ) + ( ntimes || 'hour' ) :: INTERVAL BETWEEN ")
                    .append("'").append(dateStart).append("' AND ")
                    .append("'").append(dateEnd).append("' AND ")
                    // .append("ntimes IN (")
                    // .append(hours).append(") AND ")
                    .append("stationid = '").append(stationId).append("' ")
                    .append("AND forecasttype = '3' ")
                    .append("ORDER BY datechar ASC");
            List<Map<String, Object>> hourInfo = comDisplayService.get24HourInfoFur(sql1.toString());
            Map<String, List<Object>> result = new HashMap<>();
            List<Object> rainList = new ArrayList<>();
            List<Object> maxtempList = new ArrayList<>();
            List<Object> instantwindvList = new ArrayList<>();
            List<Object> winddList = new ArrayList<>();
            List<Object> windLvList = new ArrayList<>();
            for (int i = 0; i < 13; i++) {
                if (i < hourInfoNew.size()) {
                    rainList.add(hourInfoNew.get(i).get("rain"));
                    maxtempList.add(hourInfoNew.get(i).get("maxtemp"));
                    instantwindvList.add(hourInfoNew.get(i).get("instantwindv"));
                    winddList.add(hourInfoNew.get(i).get("windd"));
                    windLvList.add(WebCtrlData.FengSuToFengJi(Double.parseDouble(hourInfoNew.get(i).get("instantwindv").toString())));
                } else {
                    rainList.add(0.0);
                    maxtempList.add(0.0);
                    instantwindvList.add(0.0);
                    winddList.add(0.0);
                    windLvList.add(0);
                }
            }
            for (int i = 0; i < 8; i++) {
                if (i < hourInfo.size()) {
                    rainList.add( hourInfo.get(i).get("rain"));
                    maxtempList.add(hourInfo.get(i).get("maxtemp"));
                    instantwindvList.add( hourInfo.get(i).get("wind"));
                    winddList.add(hourInfo.get(i).get("windd"));
                    windLvList.add(WebCtrlData.FengSuToFengJi(Double.parseDouble(hourInfo.get(i).get("wind").toString())));
                } else {
                    rainList.add(0.0);
                    maxtempList.add(0.0);
                    instantwindvList.add(0.0);
                    winddList.add(0.0);
                    windLvList.add(0);
                }
            }
            result.put("rain", rainList);
            result.put("maxtemp", maxtempList);
            result.put("instantwindv", instantwindvList);
            result.put("windd", winddList);
            result.put("windLv", windLvList);


            return Results.success("获取实况预报小时数据", 1, result);
        }  catch (Exception e){
           return Results.fail(e.getMessage());
        }

    }
    @GetMapping("/get24HourInfo1")
    @ResponseBody
    public Results get24HourInfo(String type){
        try{
             StringBuilder sql = new StringBuilder();
                // 拼接每个查询
            sql.append("SELECT m.")
                    .append(type).append(", ")
                    .append("m.stationname, ")
                    .append("EXTRACT(HOUR FROM m.observtime) + 1 AS hour_of_day ")
                    .append("FROM msgmediumsmallscale m ")
                    .append("JOIN ( SELECT MAX(observtime) AS latest_observtime\n" +
                            "    FROM msgmediumsmallscale\n" +
                            "    WHERE stationid LIKE '5%') t ")
                    .append("ON m.observtime >= t.latest_observtime - INTERVAL '24 hour' ") // 动态时间
                    .append("WHERE m.stationid LIKE '5%' ")
                    .append("AND m.city LIKE '%").append(DbConfig.CITY).append("%' ") // 注意 CITY 参数
                    .append("ORDER BY hour_of_day;");
            StringBuilder sql1 = new StringBuilder();
            String type1 = "";
            switch (type){
                case "drybulbtemp":
                    type1 = "温度";
                    break;
                case "maxtemp":
                    type1 = "最高温度";
                    break;
                case "mintemp":
                    type1 = "最低温度";
                    break;
                case "rain":
                    type1 = "雨量";
                    break;
                case "instantwindv":
                    type1 = "风速";
                    break;
                case "relhumidity":
                    type1 = "湿度";
                    break;
                case "visibility":
                    type1 = "能见度";
                    break;
                    default:
                        break;

             }

            sql1.append("SELECT elementvalue ,").
                    append("elementcolor").
                    append(" FROM contour_setting ").
                    append(" where elementtype = '").append(type1).append("'");
            // 假设 result1 存储的是雨量值和颜色范围的映射：雨量 -> 颜色
            List<Map<String, Object>> result1 = comDisplayService.getcolor(sql1.toString());
            Map<Integer, Integer> rainToColorMap = new TreeMap<>();  // 用 TreeMap 保证按雨量值升序排列

// 填充 rainToColorMap
            for (Map<String, Object> row : result1) {
                Integer rainValue = (Integer) row.get("elementvalue");  // 雨量值
                Integer colorValue = (Integer) row.get("elementcolor");  // 对应的颜色值
                rainToColorMap.put(rainValue, colorValue);
            }

// 按站点分组数据
            List<Map<String, Object>> result = comDisplayService.get24HourInfo(type, sql.toString());
            Map<String, List<Map<String, Object>>> stationData = new LinkedHashMap<>();

// 遍历每一行数据
            for (Map<String, Object> row : result) {
                String stationName = (String) row.get("stationName");
                String hourInWords = (String) row.get("hour_of_day");
                Object value = row.get(type);

                // 获取站点对应的数据列表，如果站点不存在则创建一个新的列表
                List<Map<String, Object>> stationEntries = stationData.computeIfAbsent(stationName, k -> new ArrayList<>());

                // 确保每个站点的数据按小时存储
                Map<String, Object> stationEntry = null;

                // 如果是第一次遇到该站点，创建一个新的 Map 来存储数据
                if (stationEntries.isEmpty()) {
                    stationEntry = new LinkedHashMap<>();
                    stationEntry.put("站点", stationName);
                    // 初始化1到24小时的空值
                    for (int i = 1; i <= 24; i++) {
                        stationEntry.put(i + "h", "");
                        stationEntry.put(i + "hcolor", "");  // 添加小时颜色字段
                    }
                    stationEntries.add(stationEntry);
                } else {
                    stationEntry = stationEntries.get(0); // 获取该站点的第一个条目
                }

                // 如果小时数据合法（例如1h, 2h等）
                if (hourInWords.matches("\\d+")) {
                    String hour = hourInWords + "h";  // 1h, 2h, ...

                    // 设置雨量值
                    stationEntry.put(hour, value != null ? value : "0.0");

                    // 判断该雨量值所在的颜色范围
                    Double rainValue = value != null ? Double.valueOf(value.toString()) : 0.0;
                    String color = getColorForRainValue(rainValue, rainToColorMap);  // 获取对应的颜色值

                    // 设置颜色值
                    String colorField = hour + "color";  // 1hcolor, 2hcolor, ...
                    stationEntry.put(colorField, color != null ? color : "0 ");
                }
            }

// 将站点数据转换为所需格式
            List<Map<String, Object>> tableData = new ArrayList<>();
            for (Map.Entry<String, List<Map<String, Object>>> entry : stationData.entrySet()) {
                List<Map<String, Object>> stationEntries = entry.getValue();
                tableData.addAll(stationEntries);  // 将站点的所有数据行加入结果
            }

// 返回转换后的结果
            return Results.success("获取站点过去1到24小时数据", tableData.size(), tableData);
        } catch (Exception e) {
            return Results.fail(e.getMessage());
        }
    }

    private String getColorForRainValue(Double rainValue, Map<Integer, Integer> rainToColorMap) {
        Integer color = null;  // 用 null 来表示没有找到匹配的颜色
        Integer maxRainValue = Integer.MIN_VALUE;  // 用来保存最大降水值
        Integer minRainValue = Integer.MAX_VALUE;  // 用来保存最小降水值
        Integer maxColor = 0;  // 用来保存最大降水值对应的颜色
        Integer minColor = 0;  // 用来保存最小降水值对应的颜色

        // 遍历 rainToColorMap，找出最大降水值、最小降水值及其对应颜色
        for (Map.Entry<Integer, Integer> entry : rainToColorMap.entrySet()) {
            if (entry.getKey() > maxRainValue) {
                maxRainValue = entry.getKey();
                maxColor = entry.getValue();
            }
            if (entry.getKey() < minRainValue) {
                minRainValue = entry.getKey();
                minColor = entry.getValue();
            }

            // 找到第一个满足条件的降水值，赋值颜色
            if (rainValue <= entry.getKey() && color == null) {
                color = entry.getValue();
            }
        }

        // 如果 rainValue 小于最小的降水值，返回最小降水值对应的颜色
        if (rainValue < minRainValue) {
            color = minColor;
        }

        // 如果 rainValue 超过了最大降水值，返回最大降水值对应的颜色
        if (rainValue > maxRainValue) {
            color = maxColor;
        }

        return decimalToHex(color);
    }
    public static String decimalToHex(int decimal) {
        return String.format("#%06X", decimal);
    }
    //根据经纬度获取最近站点
    public class DistanceUtil {
        // 地球半径
        private static final double EARTH_RADIUS = 6371; // 单位：千米

        /**
         * 根据经纬度计算两点之间的距离
         * @param lat1 第一点的纬度
         * @param lon1 第一点的经度
         * @param lat2 第二点的纬度
         * @param lon2 第二点的经度
         * @return 两点之间的距离，单位：千米
         */
        public double getDistance(double lat1, double lon1, double lat2, double lon2) {
            // 将角度转为弧度
            lat1 = Math.toRadians(lat1);
            lon1 = Math.toRadians(lon1);
            lat2 = Math.toRadians(lat2);
            lon2 = Math.toRadians(lon2);

            // Haversine公式
            double dlon = lon2 - lon1;
            double dlat = lat2 - lat1;
            double a = Math.pow(Math.sin(dlat / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon / 2), 2);
            double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
            return EARTH_RADIUS * c;
        }
    }
    //根据坐标点获取最近坐标
    public Map<String, Object> findNearestStation(List<Map<String, Object>> res, double frontLat, double frontLon) {
        double minDistance = Double.MAX_VALUE;
        Map<String, Object> nearestStation = null;

        DistanceUtil distanceUtil = new DistanceUtil();  // 创建实例
        for (Map<String, Object> station : res) {
            // 获取当前站点的经纬度
            double stationLat = (double) station.get("latitude");
            double stationLon = (double) station.get("longitude");

            // 计算当前站点与前端经纬度之间的距离
            double distance = distanceUtil.getDistance(frontLat, frontLon, stationLat, stationLon);

            // 如果当前距离更小，则更新最近的站点
            if (distance < minDistance) {
                minDistance = distance;
                nearestStation = station;
            }
        }

        return nearestStation;
    }
    //截取坐标点
    // private Object parseCoordinates(String pos) {
    //     // 去掉首尾的中括号
    //     pos = pos.substring(1, pos.length() - 1);
    //
    //     // 按逗号分隔每个坐标对
    //     String[] coordinatePairs = pos.split("\\},\\{");
    //
    //     List<Map<String, Double>> coordinates = new ArrayList<>();
    //
    //     for (String pair : coordinatePairs) {
    //         pair = pair.replace("{", "").replace("}", "");  // 去掉括号
    //         String[] values = pair.split(",");
    //
    //         if (values.length == 2) {
    //             double latitude = Double.parseDouble(values[0].trim());
    //             double longitude = Double.parseDouble(values[1].trim());
    //
    //             Map<String, Double> coordinate = new HashMap<>();
    //             coordinate.put("latitude", latitude);
    //             coordinate.put("longitude", longitude);
    //
    //             coordinates.add(coordinate);
    //         }
    //     }
    //
    //     return coordinates;  // 返回坐标列表
    // }
}
